Why do bind1st and bind2nd require constant function objects?
Posted
by rlbond
on Stack Overflow
See other posts from Stack Overflow
or by rlbond
Published on 2010-05-09T00:59:10Z
Indexed on
2010/05/09
1:08 UTC
Read the original article
Hit count: 289
So, I was writing a C++ program which would allow me to take control of the entire world. I was all done writing the final translation unit, but I got an error:
error C3848: expression having type 'const `anonymous-namespace'::ElementAccumulator<T,BinaryFunction>' would lose some const-volatile qualifiers in order to call 'void `anonymous-namespace'::ElementAccumulator<T,BinaryFunction>::operator ()(const point::Point &,const int &)'
with
[
T=SideCounter,
BinaryFunction=std::plus<int>
]
c:\program files (x86)\microsoft visual studio 9.0\vc\include\functional(324) : while compiling class template member function 'void std::binder2nd<_Fn2>::operator ()(point::Point &) const'
with
[
_Fn2=`anonymous-namespace'::ElementAccumulator<SideCounter,std::plus<int>>
]
c:\users\****\documents\visual studio 2008\projects\TAKE_OVER_THE_WORLD\grid_divider.cpp(361) : see reference to class template instantiation 'std::binder2nd<_Fn2>' being compiled
with
[
_Fn2=`anonymous-namespace'::ElementAccumulator<SideCounter,std::plus<int>>
]
I looked in the specifications of binder2nd
and there it was: it took a const
AdaptibleBinaryFunction.
So, not a big deal, I thought. I just used boost::bind
instead, right?
Wrong! Now my take-over-the-world program takes too long to compile (bind
is used inside a template which is instantiated quite a lot)! At this rate, my nemesis is going to take over the world first! I can't let that happen -- he uses Java!
So can someone tell me why this design decision was made? It seems like an odd decision. I guess I'll have to make some of the elements of my class mutable
for now...
© Stack Overflow or respective owner