|
Boost Users : |
Subject: [Boost-users] [boost-users][tuple] Tuple::get<0> as std::mem_fun_ref
From: Miklós Tóth (spiralfuzet_at_[hidden])
Date: 2013-08-14 05:35:19
Hi!
I have a problem with std::mem_fun_ref and boost::tuple. Here is my code:
I have small LevelSetter class. It makes a level vector indexed by a
transform_iterator value.
template <typename LevelType>
class LevelSetter {
private:
int nmb_of_elements;
public:
LevelSetter(int nmb_of_elements_) : nmb_of_elements(nmb_of_elements_) {}
template <typename TrRange>
std::vector<LevelType> set(TrRange range) {
typedef typename TrRange::first_type TrIter;
std::vector<LevelType> levels(nmb_of_elements);
for (TrIter it = range.first; it != range.second; ++it) {
levels[*it] = 0.0;
}
// much more complicated code
return levels;
}
};
Let's call it:
class MemFunRefTest
{
private:
typedef float Scalar;
typedef boost::tuple<int, Scalar> Tuple;
typedef std::vector<Tuple> Fwd;
typedef Fwd::iterator FwdIter;
typedef std::pair<FwdIter, FwdIter> FwdRange;
Fwd elements;
public:
MemFunRefTest() {
elements.push_back(Tuple(0, 400.0));
elements.push_back(Tuple(1, 120.0));
elements.push_back(Tuple(2, 150.0));
}
void fun() {
FwdRange element_range = std::make_pair(elements.begin(),
elements.end());
LevelSetter<Scalar> setter(elements.size());
setter.set(std::make_pair(
boost::make_transform_iterator(
element_range.first,
std::mem_fun_ref(&Tuple::get<0>)
),
boost::make_transform_iterator(
element_range.second,
std::mem_fun_ref(&Tuple::get<0>)
)
)
);
}
};
When I try to compile i get:
error: call of overloaded 'mem_fun_ref(<unresolved overloaded function
type>)' is ambiguous
candidates are:
c:\mingw-4.6\bin\..\lib\gcc\i686-pc-mingw32\4.6.1\..\..\..\..\include\c++\4.6.1\bits\stl_function.h:697:
std::mem_fun_ref_t<_Ret, _Tp> std::mem_fun_ref(_Ret (_Tp::*)()) [with
_Ret = int&, _Tp = boost::tuples::cons<int, boost::tuples::cons<float,
boost::tuples::null_type> >]
c:\mingw-4.6\bin\..\lib\gcc\i686-pc-mingw32\4.6.1\..\..\..\..\include\c++\4.6.1\bits\stl_function.h:702:
std::const_mem_fun_ref_t<_Ret, _Tp> std::mem_fun_ref(_Ret
(_Tp::*)()const) [with _Ret = const int&, _Tp =
boost::tuples::cons<int, boost::tuples::cons<float,
boost::tuples::null_type> >]
What am I missing?
Thanks, Miklos
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net