Issue with iostream_iterator with tuple C++ - c++11

I want to use iostream_iterator for tuple.
I have overload input operator >> for the tuple.
But compiler give compilation error.
#include <vector>
#include <iostream>
#include <algorithm>
#include <iterator>
#include <tuple>
using namespace std;
using rec_t= tuple<int, string>;
istream& operator>>(istream& strm, rec_t& r) {
strm>>get<0>(r)>>get<1>(r);
return strm;
}
int main() {
int n;
cin>>n;
vector<rec_t> ar(n);
copy_n(istream_iterator<rec_t>(cin), n, begin(ar));
return 0;
}
The compiler error message is:
-------------- Build: Debug (compiler: GNU GCC Compiler)---------------
g++ -Wall -fexceptions -std=c++11 -g -c main.cpp -o obj/Debug/main.o
In file included from /usr/include/c++/4.9/iterator:66:0,
from main.cpp:4:
/usr/include/c++/4.9/bits/stream_iterator.h: In instantiation of ‘void std::istream_iterator<_Tp, _CharT, _Traits, _Dist>::_M_read() [with _Tp = std::tuple<int, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >; _CharT = char; _Traits = std::char_traits<char>; _Dist = long int]’:
/usr/include/c++/4.9/bits/stream_iterator.h:70:17: required from ‘std::istream_iterator<_Tp, _CharT, _Traits, _Dist>::istream_iterator(std::istream_iterator<_Tp, _CharT, _Traits, _Dist>::istream_type&) [with _Tp = std::tuple<int, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >; _CharT = char; _Traits = std::char_traits<char>; _Dist = long int; std::istream_iterator<_Tp, _CharT, _Traits, _Dist>::istream_type = std::basic_istream<char>]’
main.cpp:18:39: required from here
/usr/include/c++/4.9/bits/stream_iterator.h:121:17: error: cannot bind ‘std::istream_iterator<std::tuple<int, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >::istream_type {aka std::basic_istream<char>}’ lvalue to ‘std::basic_istream<char>&&’
*_M_stream >> _M_value;
^
In file included from /usr/include/c++/4.9/iostream:40:0,
from main.cpp:2:
/usr/include/c++/4.9/istream:872:5: note: initializing argument 1 of ‘std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&&, _Tp&) [with _CharT = char; _Traits = std::char_traits<char>; _Tp = std::tuple<int, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >]’
operator>>(basic_istream<_CharT, _Traits>&& __is, _Tp& __x)
^
Process terminated with status 1 (0 minute(s), 1 second(s))
1 error(s), 3 warning(s) (0 minute(s), 1 second(s))

You've fallen victim to ADL "argument dependent lookup".
You should go look it up, because there are good explanations out there.
Basically, your operator >> should be in the same namespace as your rec_t.
But it's not - rec_t is in namespace std (since it's really std::tuple<int, std::string>), and operator >> is in the global namespace.

Related

Can't get to compile comparison of unodered_sets

I have a couple of unordered set defined as:
std::unordered_set<std::reference_wrapper<const T>, MyHash<T>, MyEqual<T>> const &map1;
std::unordered_set<std::reference_wrapper<const T>, MyHash<T>, MyEqual<T>> const &map2;
With the functors defined as:
Hash:
template<typename T>
struct MyHash
{
inline size_t operator()(
std::reference_wrapper<const T> const &obj) const noexcept
{
return reinterpret_cast<size_t>(&obj.get());
}
};
Equality:
template<typename T>
struct MyEqual
{
inline bool operator()(
std::reference_wrapper<const T> const &lhs,
std::reference_wrapper<const T> const &rhs) const
{
return (reinterpret_cast<size_t>(&lhs.get()) == reinterpret_cast<size_t>(&rhs.get()));
}
};
Basically using the memory address of the referenced object as a hash and checking if two references are equal if they share the same memory address for their underlying object.
This works fine, EXCEPT when I try to compare if two sets are identical:
if(map1 == map2)
It doesn't compile, and instead, returns:
GCC:
/opt/rh/devtoolset-8/root/usr/include/c++/8/bits/hashtable_policy.h: In instantiation of ‘bool std::__detail::_Equality<_Key, _Value, _Alloc, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits, true>::_M_equal(const __hashtable&) const [with _Key = std::reference_wrapper<const std::basic_string<char> >; _Value = std::reference_wrapper<const std::basic_string<char> >; _Alloc = std::allocator<std::reference_wrapper<const std::basic_string<char> > >; _ExtractKey = std::__detail::_Identity; _Equal = MyEqual<std::basic_string<char> >; _H1 = MyHash<std::basic_string<char> >; _H2 = std::__detail::_Mod_range_hashing; _Hash = std::__detail::_Default_ranged_hash; _RehashPolicy = std::__detail::_Prime_rehash_policy; _Traits = std::__detail::_Hashtable_traits<false, true, true>; std::__detail::_Equality<_Key, _Value, _Alloc, _ExtractKey, _Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits, true>::__hashtable = std::_Hashtable<std::reference_wrapper<const std::basic_string<char> >, std::reference_wrapper<const std::basic_string<char> >, std::allocator<std::reference_wrapper<const std::basic_string<char> > >, std::__detail::_Identity, MyEqual<std::basic_string<char> >, MyHash<std::basic_string<char> >, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<false, true, true> >]’:
/opt/rh/devtoolset-8/root/usr/include/c++/8/bits/unordered_set.h:1671:40: required from ‘bool std::operator==(const std::unordered_set<_Value1, _Hash1, _Pred1, _Alloc1>&, const std::unordered_set<_Value1, _Hash1, _Pred1, _Alloc1>&) [with _Value1 = std::reference_wrapper<const std::basic_string<char> >; _Hash1 = MyHash<std::basic_string<char> >; _Pred1 = MyEqual<std::basic_string<char> >; _Alloc1 = std::allocator<std::reference_wrapper<const std::basic_string<char> > >; _Value = int; _Hash = std::hash<int>; _Pred = std::equal_to<int>; _Alloc = std::allocator<int>]’
/home/my_test.cpp:526:28: required from here
/opt/rh/devtoolset-8/root/usr/include/c++/8/bits/hashtable_policy.h:1957:47: error: no match for ‘operator==’ (operand types are ‘const std::reference_wrapper<const std::basic_string<char> >’ and ‘const std::reference_wrapper<const std::basic_string<char> >’)
if (__ity == __other.end() || !bool(*__ity == *__itx))
~~~~~~~^~~~~~~~~
CLang:
/opt/rh/devtoolset-8/root/usr/lib/gcc/x86_64-redhat-linux/8/../../../../include/c++/8/bits/hashtable_policy.h:1957:47: fatal error: invalid operands to binary expression ('const std::reference_wrapper<const std::basic_string<char, std::char_traits<char>, std::allocator<char> > >' and 'const std::reference_wrapper<const std::basic_string<char, std::char_traits<char>, std::allocator<char> > >')
if (__ity == __other.end() || !bool(*__ity == *__itx))
~~~~~~ ^ ~~~~~~
/opt/rh/devtoolset-8/root/usr/lib/gcc/x86_64-redhat-linux/8/../../../../include/c++/8/bits/unordered_set.h:1671:23: note: in instantiation of member function 'std::__detail::_Equality<std::reference_wrapper<const std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::reference_wrapper<const std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::reference_wrapper<const std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, std::__detail::_Identity, MyEqual<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, MyHash<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<false, true, true>, true>::_M_equal' requested here
{ return __x._M_h._M_equal(__y._M_h); }
^
/home/my_test.cpp:526:25: note: in instantiation of function template specialization 'std::operator==<std::reference_wrapper<const std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, MyHash<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, MyEqual<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::reference_wrapper<const std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >' requested here
if(map1 == map2)
I can't figure out why, since I'm already providing a comparator for the equality when defining the set. I can certaily do the comparison explicitly, but since the STL already does that for me, I'd rather avoid writing redundant code.
Any ideas what I'm doing wrong? They'd be greatly appreciated.

How to get *any* example of boost::mpl::map working?

Here is my sample code. Can someone please help me with it?
#include <string>
#include <utility> //Not strictly necessary (gets imported implicitely anyway)
#include <boost/mpl/map.hpp>
#include <boost/mpl/size.hpp>
#include <boost/type_traits/is_same.hpp>
typedef boost::mpl::map<
std::pair<int,unsigned>
, std::pair<char,unsigned char>
> m;
int main()
{
std::pair<int,unsigned> b(10,10); //this works
int a = boost::mpl::size<m>::value; //this doesn't
}
The error message:
In file included from /home/adam/spack/opt/spack/linux-ubuntu16.04-x86_64/gcc-5.4.0/boost-1.67.0-xcr4z3warx5tptvihmi5biqrq7hpgw7j/include/boost/mpl/map/aux_/include_preprocessed.hpp:47:0,
from /home/adam/spack/opt/spack/linux-ubuntu16.04-x86_64/gcc-5.4.0/boost-1.67.0-xcr4z3warx5tptvihmi5biqrq7hpgw7j/include/boost/mpl/map/map10.hpp:28,
from /home/adam/spack/opt/spack/linux-ubuntu16.04-x86_64/gcc-5.4.0/boost-1.67.0-xcr4z3warx5tptvihmi5biqrq7hpgw7j/include/boost/mpl/map/map20.hpp:19,
from /home/adam/spack/opt/spack/linux-ubuntu16.04-x86_64/gcc-5.4.0/boost-1.67.0-xcr4z3warx5tptvihmi5biqrq7hpgw7j/include/boost/mpl/map.hpp:36,
from /home/adam/c++/tests/simple_test/test2.cpp:3:
/home/adam/spack/opt/spack/linux-ubuntu16.04-x86_64/gcc-5.4.0/boost-1.67.0-xcr4z3warx5tptvihmi5biqrq7hpgw7j/include/boost/mpl/map/aux_/preprocessed/typeof_based/map10.hpp: In instantiation of ‘struct boost::mpl::map2<std::pair<int, unsigned int>, std::pair<char, unsigned char> >’:
/home/adam/spack/opt/spack/linux-ubuntu16.04-x86_64/gcc-5.4.0/boost-1.67.0-xcr4z3warx5tptvihmi5biqrq7hpgw7j/include/boost/mpl/aux_/preprocessed/gcc/map.hpp:51:8: required from ‘struct boost::mpl::map<std::pair<int, unsigned int>, std::pair<char, unsigned char> >’
/home/adam/spack/opt/spack/linux-ubuntu16.04-x86_64/gcc-5.4.0/boost-1.67.0-xcr4z3warx5tptvihmi5biqrq7hpgw7j/include/boost/mpl/aux_/has_tag.hpp:20:1: required by substitution of ‘template<class U> static char (& boost::mpl::aux::has_tag<boost::mpl::map<std::pair<int, unsigned int>, std::pair<char, unsigned char> >, mpl_::bool_<false> >::gcc_3_2_wknd::test<U>(const volatile boost::mpl::aux::type_wrapper<T>*, boost::mpl::aux::type_wrapper<typename U::tag>*))[2] [with U = boost::mpl::map<std::pair<int, unsigned int>, std::pair<char, unsigned char> >]’
/home/adam/spack/opt/spack/linux-ubuntu16.04-x86_64/gcc-5.4.0/boost-1.67.0-xcr4z3warx5tptvihmi5biqrq7hpgw7j/include/boost/mpl/aux_/has_tag.hpp:20:1: required from ‘const bool boost::mpl::aux::has_tag<boost::mpl::map<std::pair<int, unsigned int>, std::pair<char, unsigned char> >, mpl_::bool_<false> >::value’
/home/adam/spack/opt/spack/linux-ubuntu16.04-x86_64/gcc-5.4.0/boost-1.67.0-xcr4z3warx5tptvihmi5biqrq7hpgw7j/include/boost/mpl/aux_/has_tag.hpp:20:1: required from ‘struct boost::mpl::aux::has_tag<boost::mpl::map<std::pair<int, unsigned int>, std::pair<char, unsigned char> >, mpl_::bool_<false> >’
/home/adam/spack/opt/spack/linux-ubuntu16.04-x86_64/gcc-5.4.0/boost-1.67.0-xcr4z3warx5tptvihmi5biqrq7hpgw7j/include/boost/mpl/sequence_tag.hpp:110:8: required from ‘struct boost::mpl::sequence_tag<boost::mpl::map<std::pair<int, unsigned int>, std::pair<char, unsigned char> > >’
/home/adam/spack/opt/spack/linux-ubuntu16.04-x86_64/gcc-5.4.0/boost-1.67.0-xcr4z3warx5tptvihmi5biqrq7hpgw7j/include/boost/mpl/size.hpp:29:8: required from ‘struct boost::mpl::size<boost::mpl::map<std::pair<int, unsigned int>, std::pair<char, unsigned char> > >’
/home/adam/c++/tests/simple_test/test2.cpp:15:29: required from here
/home/adam/spack/opt/spack/linux-ubuntu16.04-x86_64/gcc-5.4.0/boost-1.67.0-xcr4z3warx5tptvihmi5biqrq7hpgw7j/include/boost/mpl/map/aux_/preprocessed/typeof_based/map10.hpp:31:8: error: no type named ‘first’ in ‘struct std::pair<char, unsigned char>’
struct map2
^~~~
In file included from /home/adam/c++/tests/simple_test/test2.cpp:4:0:
/home/adam/spack/opt/spack/linux-ubuntu16.04-x86_64/gcc-5.4.0/boost-1.67.0-xcr4z3warx5tptvihmi5biqrq7hpgw7j/include/boost/mpl/size.hpp: In instantiation of ‘struct boost::mpl::size<boost::mpl::map<std::pair<int, unsigned int>, std::pair<char, unsigned char> > >’:
/home/adam/c++/tests/simple_test/test2.cpp:15:29: required from here
/home/adam/spack/opt/spack/linux-ubuntu16.04-x86_64/gcc-5.4.0/boost-1.67.0-xcr4z3warx5tptvihmi5biqrq7hpgw7j/include/boost/mpl/size.hpp:29:8: error: no class template named ‘apply’ in ‘struct boost::mpl::size_impl<boost::mpl::non_sequence_tag>’
struct size
^~~~
/home/adam/c++/tests/simple_test/test2.cpp: In function ‘int main()’:
/home/adam/c++/tests/simple_test/test2.cpp:15:31: error: ‘value’ is not a member of ‘boost::mpl::size<boost::mpl::map<std::pair<int, unsigned int>, std::pair<char, unsigned char> > >’
int a = boost::mpl::size<m>::value; //this doesn't
^~~~~
/home/adam/c++/tests/simple_test/test2.cpp:15:6: warning: unused variable ‘a’ [-Wunused-variable]
int a = boost::mpl::size<m>::value; //this doesn't
^
CMakeFiles/libsimple_test.dir/build.make:62: recipe for target 'CMakeFiles/libsimple_test.dir/test2.cpp.o' failed
make[2]: *** [CMakeFiles/libsimple_test.dir/test2.cpp.o] Error 1
CMakeFiles/Makefile2:142: recipe for target 'CMakeFiles/libsimple_test.dir/all' failed
make[1]: *** [CMakeFiles/libsimple_test.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
I use C++11 on GCC 7.3.0 and libboost 1.67.0 on Ubuntu 16.04 64bit.
By chance I found a solution: Don't use the standard std::pair, but rather use the re-invented boost::mpl::pair. After simple replacing std::pair into boost::mpl::pair the sample code compiles and runs properly... which leads to another question.

I am getting issues, when compiling my code in codeblocks C++

I am trying to do my assignment for data structures class. The question is 1) Compile with UNIT_TEST defined and then run with -d yes to see the time it takes in seconds. Report that time in submission box along with the time you found when testing Selection Sort. Which is faster?
i am having trouble with understanding, what i am doing wrong. I am getting this error :
g++ -o bin/Debug/algAnalysis obj/Debug/main.o
Undefined symbols for architecture x86_64:
"Catch::NameAndTags::NameAndTags(Catch::StringRef const&, Catch::StringRef const&)", referenced from:
___cxx_global_var_init in main.o
"Catch::StringMaker<int, void>::convert(int)", referenced from:
std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > Catch::Detail::stringify<int>(int const&) in main.o
"Catch::makeTestInvoker(void (*)())", referenced from:
___cxx_global_var_init in main.o
"Catch::AssertionHandler::handleExpr(Catch::ITransientExpression const&)", referenced from:
____C_A_T_C_H____T_E_S_T____0() in main.o
"Catch::AssertionHandler::handleUnexpectedInflightException()", referenced from:
____C_A_T_C_H____T_E_S_T____0() in main.o
"Catch::AssertionHandler::complete()", referenced from:
____C_A_T_C_H____T_E_S_T____0() in main.o
"Catch::AssertionHandler::AssertionHandler(Catch::StringRef, Catch::SourceLineInfo const&, Catch::StringRef, Catch::ResultDisposition::Flags)", referenced from:
____C_A_T_C_H____T_E_S_T____0() in main.o
"Catch::ITransientExpression::~ITransientExpression()", referenced from:
Catch::MatchExpr<std::__1::vector<int, std::__1::allocator<int> >, Catch::Matchers::Impl::MatchNotOf<std::__1::vector<int, std::__1::allocator<int> > > >::MatchExpr(std::__1::vector<int, std::__1::allocator<int> > const&, Catch::Matchers::Impl::MatchNotOf<std::__1::vector<int, std::__1::allocator<int> > > const&, Catch::StringRef) in main.o
Catch::MatchExpr<std::__1::vector<int, std::__1::allocator<int> >, Catch::Matchers::Impl::MatchNotOf<std::__1::vector<int, std::__1::allocator<int> > > >::~MatchExpr() in main.o
Catch::MatchExpr<std::__1::vector<int, std::__1::allocator<int> >, Catch::Matchers::Vector::EqualsMatcher<int> >::MatchExpr(std::__1::vector<int, std::__1::allocator<int> > const&, Catch::Matchers::Vector::EqualsMatcher<int> const&, Catch::StringRef) in main.o
Catch::MatchExpr<std::__1::vector<int, std::__1::allocator<int> >, Catch::Matchers::Vector::EqualsMatcher<int> >::~MatchExpr() in main.o
"Catch::ReusableStringStream::ReusableStringStream()", referenced from:
std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > Catch::Detail::rangeToString<std::__1::__wrap_iter<int const*> >(std::__1::__wrap_iter<int const*>, std::__1::__wrap_iter<int const*>) in main.o
"Catch::ReusableStringStream::~ReusableStringStream()", referenced from:
std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > Catch::Detail::rangeToString<std::__1::__wrap_iter<int const*> >(std::__1::__wrap_iter<int const*>, std::__1::__wrap_iter<int const*>) in main.o
"Catch::Detail::unprintableString", referenced from:
Catch::MatchExpr<std::__1::vector<int, std::__1::allocator<int> >, Catch::Matchers::Impl::MatchNotOf<std::__1::vector<int, std::__1::allocator<int> > > >::streamReconstructedExpression(std::__1::basic_ostream<char, std::__1::char_traits<char> >&) const in main.o
Catch::MatchExpr<std::__1::vector<int, std::__1::allocator<int> >, Catch::Matchers::Vector::EqualsMatcher<int> >::streamReconstructedExpression(std::__1::basic_ostream<char, std::__1::char_traits<char> >&) const in main.o
"Catch::AutoReg::AutoReg(Catch::ITestInvoker*, Catch::SourceLineInfo const&, Catch::StringRef const&, Catch::NameAndTags const&)", referenced from:
___cxx_global_var_init in main.o
"Catch::AutoReg::~AutoReg()", referenced from:
___cxx_global_var_init in main.o
"Catch::Matchers::Impl::MatcherUntypedBase::~MatcherUntypedBase()", referenced from:
Catch::Matchers::Impl::MatcherBase<std::__1::vector<int, std::__1::allocator<int> > >::~MatcherBase() in main.o
"Catch::StringRef::StringRef(char const*)", referenced from:
____C_A_T_C_H____T_E_S_T____0() in main.o
___cxx_global_var_init in main.o
(maybe you meant: __ZN5Catch9StringRefC1EPKcm)
"Catch::operator<<(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, Catch::StringRef const&)", referenced from:
Catch::MatchExpr<std::__1::vector<int, std::__1::allocator<int> >, Catch::Matchers::Impl::MatchNotOf<std::__1::vector<int, std::__1::allocator<int> > > >::streamReconstructedExpression(std::__1::basic_ostream<char, std::__1::char_traits<char> >&) const in main.o
Catch::MatchExpr<std::__1::vector<int, std::__1::allocator<int> >, Catch::Matchers::Vector::EqualsMatcher<int> >::streamReconstructedExpression(std::__1::basic_ostream<char, std::__1::char_traits<char> >&) const in main.o
"Stack::pop(int&)", referenced from:
SortClass<int>::sort(int*, int, int) in main.o
"Stack::push(int)", referenced from:
SortClass<int>::sort(int*, int, int) in main.o
"Stack::Stack(int)", referenced from:
SortClass<int>::sort(int*, int, int) in main.o
"Stack::~Stack()", referenced from:
SortClass<int>::sort(int*, int, int) in main.o
"Catch::ReusableStringStream::str() const", referenced from:
std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > Catch::Detail::rangeToString<std::__1::__wrap_iter<int const*> >(std::__1::__wrap_iter<int const*>, std::__1::__wrap_iter<int const*>) in main.o
"Catch::Matchers::Impl::MatcherUntypedBase::toString() const", referenced from:
Catch::MatchExpr<std::__1::vector<int, std::__1::allocator<int> >, Catch::Matchers::Impl::MatchNotOf<std::__1::vector<int, std::__1::allocator<int> > > >::streamReconstructedExpression(std::__1::basic_ostream<char, std::__1::char_traits<char> >&) const in main.o
Catch::Matchers::Impl::MatchNotOf<std::__1::vector<int, std::__1::allocator<int> > >::describe() const in main.o
Catch::MatchExpr<std::__1::vector<int, std::__1::allocator<int> >, Catch::Matchers::Vector::EqualsMatcher<int> >::streamReconstructedExpression(std::__1::basic_ostream<char, std::__1::char_traits<char> >&) const in main.o
"typeinfo for Catch::ITransientExpression", referenced from:
typeinfo for Catch::MatchExpr<std::__1::vector<int, std::__1::allocator<int> >, Catch::Matchers::Impl::MatchNotOf<std::__1::vector<int, std::__1::allocator<int> > > > in main.o
typeinfo for Catch::MatchExpr<std::__1::vector<int, std::__1::allocator<int> >, Catch::Matchers::Vector::EqualsMatcher<int> > in main.o
"typeinfo for Catch::Matchers::Impl::MatcherUntypedBase", referenced from:
typeinfo for Catch::Matchers::Impl::MatcherBase<std::__1::vector<int, std::__1::allocator<int> > > in main.o
"vtable for Catch::ITransientExpression", referenced from:
Catch::ITransientExpression::ITransientExpression(bool, bool) in main.o
NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
"vtable for Catch::Matchers::Impl::MatcherUntypedBase", referenced from:
Catch::Matchers::Impl::MatcherUntypedBase::MatcherUntypedBase(Catch::Matchers::Impl::MatcherUntypedBase const&) in main.o
Catch::Matchers::Impl::MatcherUntypedBase::MatcherUntypedBase() in main.o
NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Process terminated with status 1 (0 minute(s), 0 second(s))
Here is my code so far:
#define CATCH_CONFIG_MAI
#define UNIT_TEST
#include <iostream>
#include <fstream>
#include <vector>
#ifdef UNIT_TEST
#include "catch.hpp"
#endif // UNIT_TEST
#include "stack.h"
using namespace std;
template <class T>
class SortClass
{
private:
void swap(T &a, T&b);
int split(T a[], int first, int last);
public:
void sort(T a[], int first, int last);
};
template <typename T>
int SortClass <T>::split (T arr[], int first, int last)
{
T x= arr[last];
int i= (first-1);
for (int j=first; j <= last-1; j++)
{
if (arr[j]<= x)
{
i++;
swap (arr[i], arr[j]);
}
}
swap (arr[i+1], arr[last]);
return (i+1);
}
template <class T>
void SortClass <T>::sort(T a[], int first, int last)
{
Stack stack;
stack.push (first);
stack.push (last);
while (not stack.isEmpty())
{
stack.pop(last);
stack.pop(first);
int s= split (a, first, last);
if (s-1>first )
{
stack.push(first);
stack.push(s-1);
}
if (s+1<last)
{
stack.push(s+1);
stack.push(last);
}
}
}
template <class T>
void SortClass <T>:: swap(T &a, T &b)
{
T temp=a;
a=b;
b=temp;
}
#ifndef UNIT_TEST
int main ()
{
const int N=10;
int x1[N]={1,3,5,6,4,2,8,9,7};
for (auto e: x1) std:: cout << e << " ";
std:: cout << std:: endl;
SortClass <int> s; s.sort(x1,0,N-1);
for (auto e: x1) std:: cout << e << " ";
std:: cout << std:: endl;
}
#endif
#ifdef UNIT_TEST
using Catch::Matchers::Equals;
TEST_CASE("A fast sort")
{
const int N = 6;
int x1[N] = { 1, 3, 5, 6, 4, 2 };
int x2[N] = { 1, 2, 3, 4, 5, 6 };
vector<int> v1(x1, x1 + N);
vector<int> v2(x2, x2 + N);
REQUIRE_THAT(v1, not Equals(v2));
SortClass<int> s;
s.sort(x1, 0, N - 1);
vector<int> v0(x1, x1 + N);
REQUIRE_THAT(v0, Equals(v2));
const int M = 100000;
int x3[M]; int x4[M];
ifstream ifs1("numbers");
for (auto &e : x3)
ifs1 >> e;
ifstream ifs2("sorted");
for (auto &e : x4)
ifs2 >> e;
s.sort(x3, 0, M - 1);
vector<int> v3(x3, x3 + M);
vector<int> v4(x4, x4 + M);
REQUIRE_THAT(v3, Equals(v4));
}
#endif
#define CATCH_CONFIG_MAIN Must be defined before #include "catch.hpp".
You have #define CATCH_CONFIG_MAI.

unordered_map with IP address as a key

I am trying to build a list of linked list in my application. The list will contains unique IP addresses,and for each IP addres I have a list of applications. I am trying to build it using unordered_map to take Boost::boost::asio::ip::address as a the key and std::list as value:
#include <boost/unordered/unordered_map.hpp>
#include <iostream>
#include <list>
using namespace boost::asio::ip;
using namespace std;
typedef int ApplicationID;
typedef address IPAddress;
typedef list <ApplicationID> APP_LIST;
typedef boost::unordered::unordered_map <IPAddress, APP_LIST> USER_MAP;
USER_MAP user_map;
Later I try to get the list associated with an IP address as following:
APP_LIST *list = &user_map[ip];
But I get errors in the compilation, so could you please specify what's the problem?
Is it possible to use Boost:IPaddress as a key function?
Another question is it possible to use char[some_size] as a key value?
Error Output:
In file included from /boost/functional/hash/hash.hpp:535:0,
from /boost/functional/hash.hpp:6,
from /boost/unordered/unordered_map.hpp:21,
from ipc_module.cpp:18:
/boost/functional/hash/extensions.hpp: In member function ‘std::size_t boost::hash<T>::operator()(const T&) const [with T = boost::asio::ip::address, std::size_t = long unsigned int]’:
/boost/unordered/detail/unique.hpp:331:55: instantiated from ‘boost::unordered::detail::table_impl<Types>::value_type& boost::unordered::detail::table_impl<Types>::operator[](const key_type&) [with Types = boost::unordered::detail::map<std::allocator<std::pair<const boost::asio::ip::address, std::list<int> > >, boost::asio::ip::address, std::list<int>, boost::hash<boost::asio::ip::address>, std::equal_to<boost::asio::ip::address> >, boost::unordered::detail::table_impl<Types>::value_type = std::pair<const boost::asio::ip::address, std::list<int> >, boost::unordered::detail::table_impl<Types>::key_type = boost::asio::ip::address]’
/boost/unordered/unordered_map.hpp:1192:26: instantiated from ‘boost::unordered::unordered_map<K, T, H, P, A>::mapped_type& boost::unordered::unordered_map<K, T, H, P, A>::operator[](const key_type&) [with K = boost::asio::ip::address, T = std::list<int>, H = boost::hash<boost::asio::ip::address>, P = std::equal_to<boost::asio::ip::address>, A = std::allocator<std::pair<const boost::asio::ip::address, std::list<int> > >, boost::unordered::unordered_map<K, T, H, P, A>::mapped_type = std::list<int>, boost::unordered::unordered_map<K, T, H, P, A>::key_type = boost::asio::ip::address]’
ipc_module.cpp:175:40: instantiated from here
/boost/functional/hash/extensions.hpp:176:34: error: no matching function for call to ‘hash_value(const boost::asio::ip::address&)’
/boost/functional/hash/extensions.hpp:176:34: note: candidates are:
/boost/smart_ptr/shared_ptr.hpp:708:33: note: template<class T> std::size_t boost::hash_value(const boost::shared_ptr<T>&)
/boost/functional/hash/hash.hpp:144:24: note: std::size_t boost::hash_value(bool)
/boost/functional/hash/hash.hpp:144:24: note: no known conversion for argument 1 from ‘const boost::asio::ip::address’ to ‘bool’
/boost/functional/hash/hash.hpp:149:24: note: std::size_t boost::hash_value(char)
/boost/functional/hash/hash.hpp:149:24: note: no known conversion for argument 1 from ‘const boost::asio::ip::address’ to ‘char’
/boost/functional/hash/hash.hpp:154:24: note: std::size_t boost::hash_value(unsigned char)
/boost/functional/hash/hash.hpp:154:24: note: no known conversion for argument 1 from ‘const boost::asio::ip::address’ to ‘unsigned char’
/boost/functional/hash/hash.hpp:159:24: note: std::size_t boost::hash_value(signed char)
/boost/functional/hash/hash.hpp:159:24: note: no known conversion for argument 1 from ‘const boost::asio::ip::address’ to ‘signed char’
/boost/functional/hash/hash.hpp:164:24: note: std::size_t boost::hash_value(short int)
/boost/functional/hash/hash.hpp:164:24: note: no known conversion for argument 1 from ‘const boost::asio::ip::address’ to ‘short int’
/boost/functional/hash/hash.hpp:169:24: note: std::size_t boost::hash_value(short unsigned int)
/boost/functional/hash/hash.hpp:169:24: note: no known conversion for argument 1 from ‘const boost::asio::ip::address’ to ‘short unsigned int’
/boost/functional/hash/hash.hpp:174:24: note: std::size_t boost::hash_value(int)
/boost/functional/hash/hash.hpp:174:24: note: no known conversion for argument 1 from ‘const boost::asio::ip::address’ to ‘int’
/boost/functional/hash/hash.hpp:179:24: note: std::size_t boost::hash_value(unsigned int)
/boost/functional/hash/hash.hpp:179:24: note: no known conversion for argument 1 from ‘const boost::asio::ip::address’ to ‘unsigned int’
/boost/functional/hash/hash.hpp:184:24: note: std::size_t boost::hash_value(long int)
/boost/functional/hash/hash.hpp:184:24: note: no known conversion for argument 1 from ‘const boost::asio::ip::address’ to ‘long int’
/boost/functional/hash/hash.hpp:189:24: note: std::size_t boost::hash_value(long unsigned int)
/boost/functional/hash/hash.hpp:189:24: note: no known conversion for argument 1 from ‘const boost::asio::ip::address’ to ‘long unsigned int’
/boost/functional/hash/hash.hpp:195:24: note: std::size_t boost::hash_value(wchar_t)
/boost/functional/hash/hash.hpp:195:24: note: no known conversion for argument 1 from ‘const boost::asio::ip::address’ to ‘wchar_t’
/boost/functional/hash/hash.hpp:202:24: note: std::size_t boost::hash_value(boost::long_long_type)
/boost/functional/hash/hash.hpp:202:24: note: no known conversion for argument 1 from ‘const boost::asio::ip::address’ to ‘boost::long_long_type {aka long long int}’
/boost/functional/hash/hash.hpp:207:24: note: std::size_t boost::hash_value(boost::ulong_long_type)
/boost/functional/hash/hash.hpp:207:24: note: no known conversion for argument 1 from ‘const boost::asio::ip::address’ to ‘boost::ulong_long_type {aka long long unsigned int}’
/boost/functional/hash/hash.hpp:215:36: note: template<class T> std::size_t boost::hash_value(T* const&)
/boost/functional/hash/hash.hpp:308:24: note: template<class T, unsigned int N> std::size_t boost::hash_value(const T (&)[N])
/boost/functional/hash/hash.hpp:314:24: note: template<class T, unsigned int N> std::size_t boost::hash_value(T (&)[N])
/boost/functional/hash/hash.hpp:327:24: note: std::size_t boost::hash_value(float)
/boost/functional/hash/hash.hpp:327:24: note: no known conversion for argument 1 from ‘const boost::asio::ip::address’ to ‘float’
/boost/functional/hash/hash.hpp:332:24: note: std::size_t boost::hash_value(double)
/boost/functional/hash/hash.hpp:332:24: note: no known conversion for argument 1 from ‘const boost::asio::ip::address’ to ‘double’
/boost/functional/hash/hash.hpp:337:24: note: std::size_t boost::hash_value(long double)
/boost/functional/hash/hash.hpp:337:24: note: no known conversion for argument 1 from ‘const boost::asio::ip::address’ to ‘long double’
/boost/functional/hash/hash.hpp:321:24: note: template<class Ch, class A> std::size_t boost::hash_value(const std::basic_string<Ch, std::char_traits<_CharT>, A>&)
/boost/functional/hash/hash.hpp:343:24: note: std::size_t boost::hash_value(std::type_index)
/boost/functional/hash/hash.hpp:343:24: note: no known conversion for argument 1 from ‘const boost::asio::ip::address’ to ‘std::type_index’
/boost/functional/hash/extensions.hpp:54:17: note: template<class A, class B> std::size_t boost::hash_value(const std::pair<_T1, _T2>&)
/boost/functional/hash/extensions.hpp:63:17: note: template<class T, class A> std::size_t boost::hash_value(const std::vector<_Tp, _Alloc>&)
/boost/functional/hash/extensions.hpp:69:17: note: template<class T, class A> std::size_t boost::hash_value(const std::list<_Tp, _Alloc>&)
/boost/functional/hash/extensions.hpp:75:17: note: template<class T, class A> std::size_t boost::hash_value(const std::deque<_Tp, _Alloc>&)
/boost/functional/hash/extensions.hpp:81:17: note: template<class K, class C, class A> std::size_t boost::hash_value(const std::set<_Key, _Compare, _Alloc>&)
/boost/functional/hash/extensions.hpp:87:17: note: template<class K, class C, class A> std::size_t boost::hash_value(const std::multiset<_Key, _Compare, _Alloc>&)
/boost/functional/hash/extensions.hpp:93:17: note: template<class K, class T, class C, class A> std::size_t boost::hash_value(const std::map<_Key, _Tp, _Compare, _Alloc>&)
/boost/functional/hash/extensions.hpp:99:17: note: template<class K, class T, class C, class A> std::size_t boost::hash_value(const std::multimap<_Key, _Tp, _Compare, _Alloc>&)
/boost/functional/hash/extensions.hpp:105:17: note: template<class T> std::size_t boost::hash_value(const std::complex<_Tp>&)
/boost/functional/hash/extensions.hpp:177:9: warning: control reaches end of non-void function [-Wreturn-type]
/boost/asio/error.hpp: At global scope:
/boost/asio/error.hpp:244:45: warning: ‘boost::asio::error::system_category’ defined but not used [-Wunused-variable]
/boost/asio/error.hpp:246:45: warning: ‘boost::asio::error::netdb_category’ defined but not used [-Wunused-variable]
/boost/asio/error.hpp:248:45: warning: ‘boost::asio::error::addrinfo_category’ defined but not used [-Wunused-variable]
/boost/asio/error.hpp:250:45: warning: ‘boost::asio::error::misc_category’ defined but not used [-Wunused-variable]
Here's what I came up with after a brief inspection of the class interface for ip::address.
I would like to note that it's pretty wasteful to use. Especially if you happen to know that all addresses are ipv4, e.g. I'd prefer to key by ulong then.
namespace boost
{
template <>
struct hash<IPAddress>
{
size_t operator()(IPAddress const& v) const {
if (v.is_v4())
return v.to_v4().to_ulong();
if (v.is_v6())
{
auto const& range = v.to_v6().to_bytes();
return hash_range(range.begin(), range.end());
}
if (v.is_unspecified())
{
// guaranteed to be random: chosen by fair dice roll
return static_cast<size_t>(0x4751301174351161ul);
}
return hash_value(v.to_string());
}
};
}
See it Live on Coliru:
#include <boost/asio.hpp>
#include <boost/unordered/unordered_map.hpp>
#include <iostream>
#include <list>
typedef int ApplicationID;
typedef boost::asio::ip::address IPAddress;
typedef std::list<ApplicationID> APP_LIST;
typedef boost::unordered::unordered_map<IPAddress, APP_LIST> USER_MAP;
namespace boost
{
template <>
struct hash<IPAddress>
{
size_t operator()(IPAddress const& v) const {
if (v.is_v4())
return v.to_v4().to_ulong();
if (v.is_v6())
{
auto const& range = v.to_v6().to_bytes();
return hash_range(range.begin(), range.end());
}
if (v.is_unspecified())
return 0x4751301174351161ul;
return hash_value(v.to_string());
}
};
}
int main()
{
USER_MAP map;
map.insert({ {}, {} });
}
This is an old question, but I recently came across the same issue while writing a game in c++17.
This is how I solved it:
struct endpoint_hash
{
std::size_t operator()(boost::asio::ip::udp::endpoint const& ep) const noexcept
{
auto accum = std::size_t(0);
auto combine = [&accum](auto&& arg) {
boost::hash_combine(accum, arg);
};
combine(ep.port());
if (auto&& addr = ep.address(); addr.is_v4())
{
combine(addr.to_v4().to_ulong());
}
else
{
combine(addr.to_v6().to_bytes());
}
combine(ep.port());
return accum;
}
};
std::unordered_map<boost::asio::ip::udp::endpoint, std::shared_ptr<game_client>, endpoint_hash> cache_;
It will work if you write a hash function for IPaddress.

c++ functional / std::bind doesn't compile with Apple Clang

Here is a short version of the code I try to compile.
#include <iostream>
#include <functional>
#include <memory>
void foo(std::shared_ptr<int> b, unsigned int i)
{
std::cout << *b << " - " << i << std::endl;
}
int main()
{
using namespace std::placeholders;
typedef std::function<void(std::shared_ptr<int> b, unsigned int i)> Foo;
typedef std::function<void(unsigned int code)> Bar;
Foo f1 = foo;
Bar f2 = std::bind(f1, std::make_shared<int>(10), _1);
f2(0);
return 0;
}
g++-4.7 --version gives g++-4.7 (GCC) 4.7.1
g++-4.7 -std=c++11 test.cpp && ./a.out
10 - 0
c++ --version gives Apple clang version 4.0 (tags/Apple/clang-421.0.60) (based on LLVM 3.1svn)
c++ -std=c++11 -stdlib=libc++ test.cpp
In file included from test.cpp:3:
In file included from /usr/bin/../lib/c++/v1/iostream:38:
In file included from /usr/bin/../lib/c++/v1/ios:216:
In file included from /usr/bin/../lib/c++/v1/__locale:18:
In file included from /usr/bin/../lib/c++/v1/mutex:177:
/usr/bin/../lib/c++/v1/functional:1642:8: error: no type named 'type' in 'std::__1::__invoke_of<std::__1::function<void (std::__1::shared_ptr<int>, unsigned int)> &,
std::__1::shared_ptr<int> &, std::__1::shared_ptr<int> &&>'
>::type type;
~~~^~~~
/usr/bin/../lib/c++/v1/functional:1721:18: note: in instantiation of template class 'std::__1::__bind_return<std::__1::function<void (std::__1::shared_ptr<int>, unsigned int)>,
std::__1::tuple<std::__1::shared_ptr<int>, std::__1::placeholders::__ph<1>>, std::__1::tuple<std::__1::shared_ptr<int> &&, unsigned int &&>>' requested here
typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type
^
/usr/bin/../lib/c++/v1/functional:1722:9: note: while substituting deduced template arguments into function template 'operator()'
[with _Args = <std::__1::shared_ptr<int>, unsigned int>]
operator()(_Args&& ...__args)
^
/usr/bin/../lib/c++/v1/type_traits:2971:1: note: while substituting deduced template arguments into function template '__invoke' [with _Fp = std::__1::__bind<std::__1::function<void
(std::__1::shared_ptr<int>, unsigned int)> &, std::__1::shared_ptr<int>, std::__1::placeholders::__ph<1> &> &, _Args = <no value>]
__invoke(_Fp&& __f, _Args&& ...__args)
^
/usr/bin/../lib/c++/v1/type_traits:2989:11: note: in instantiation of template class 'std::__1::__invokable_imp<std::__1::__bind<std::__1::function<void
(std::__1::shared_ptr<int>, unsigned int)> &, std::__1::shared_ptr<int>, std::__1::placeholders::__ph<1> &> &, std::__1::shared_ptr<int>, unsigned int>' requested here
__invokable_imp<_Fp, _Args...>::value>
^
/usr/bin/../lib/c++/v1/functional:1115:33: note: in instantiation of template class 'std::__1::__invokable<std::__1::__bind<std::__1::function<void
(std::__1::shared_ptr<int>, unsigned int)> &, std::__1::shared_ptr<int>, std::__1::placeholders::__ph<1> &> &, std::__1::shared_ptr<int>, unsigned int>' requested here
template <class _Fp, bool = __invokable<_Fp&, _ArgTypes...>::value>
^
/usr/bin/../lib/c++/v1/functional:1141:35: note: (skipping 13 contexts in backtrace; use -ftemplate-backtrace-limit=0 to see all)
typename enable_if<__callable<_Fp>::value>::type* = 0);
^
/usr/bin/../lib/c++/v1/memory:2218:20: note: in instantiation of template class 'std::__1::is_nothrow_move_constructible<std::__1::__bind<std::__1::function<void
(std::__1::shared_ptr<int>, unsigned int)> &, std::__1::shared_ptr<int>, std::__1::placeholders::__ph<1> &>>' requested here
_NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
^
/usr/bin/../lib/c++/v1/__config:253:34: note: expanded from macro '_NOEXCEPT_'
# define _NOEXCEPT_(x) noexcept(x)
^
/usr/bin/../lib/c++/v1/memory:2386:15: note: in instantiation of template class 'std::__1::__libcpp_compressed_pair_imp<std::__1::__bind<std::__1::function<void
(std::__1::shared_ptr<int>, unsigned int)> &, std::__1::shared_ptr<int>, std::__1::placeholders::__ph<1> &>, std::__1::allocator<std::__1::__bind<std::__1::function<void
(std::__1::shared_ptr<int>, unsigned int)> &, std::__1::shared_ptr<int>, std::__1::placeholders::__ph<1> &>>, 2>' requested here
: private __libcpp_compressed_pair_imp<_T1, _T2>
^
/usr/bin/../lib/c++/v1/functional:988:36: note: in instantiation of template class 'std::__1::__compressed_pair<std::__1::__bind<std::__1::function<void
(std::__1::shared_ptr<int>, unsigned int)> &, std::__1::shared_ptr<int>, std::__1::placeholders::__ph<1> &>, std::__1::allocator<std::__1::__bind<std::__1::function<void
(std::__1::shared_ptr<int>, unsigned int)> &, std::__1::shared_ptr<int>, std::__1::placeholders::__ph<1> &>>>' requested here
__compressed_pair<_Fp, _Alloc> __f_;
^
/usr/bin/../lib/c++/v1/functional:1273:13: note: in instantiation of template class 'std::__1::__function::__func<std::__1::__bind<std::__1::function<void
(std::__1::shared_ptr<int>, unsigned int)> &, std::__1::shared_ptr<int>, std::__1::placeholders::__ph<1> &>, std::__1::allocator<std::__1::__bind<std::__1::function<void
(std::__1::shared_ptr<int>, unsigned int)> &, std::__1::shared_ptr<int>, std::__1::placeholders::__ph<1> &>>, void (unsigned int)>' requested here
if (sizeof(_FF) <= sizeof(__buf_) && is_nothrow_copy_constructible<_Fp>::value)
^
test.cpp:21:12: note: in instantiation of function template specialization 'std::__1::function<void (unsigned int)>::function<std::__1::__bind<std::__1::function<void
(std::__1::shared_ptr<int>, unsigned int)> &, std::__1::shared_ptr<int>, std::__1::placeholders::__ph<1> &> >' requested here
Bar f2 = std::bind(f1, std::make_shared<int>(10), _1);
^
1 error generated.
Is there something wrong with my code?
Thanks.
Sorry about the bug.
This looks like a duplicate of:
http://llvm.org/bugs/show_bug.cgi?id=15295
Here is a patch that fixes it:
Index: include/functional
===================================================================
--- include/functional (revision 175515)
+++ include/functional (working copy)
## -1624,16 +1624,38 ##
: public ____mu_return<_Ti,
__is_reference_wrapper<_Ti>::value,
is_bind_expression<_Ti>::value,
- 0 < is_placeholder<_Ti>::value,
+ 0 < is_placeholder<_Ti>::value &&
+ is_placeholder<_Ti>::value <= tuple_size<_TupleUj>::value,
_TupleUj>
{
};
template <class _Fp, class _BoundArgs, class _TupleUj>
+struct _is_valid_bind_return
+{
+ static const bool value = false;
+};
+
+template <class _Fp, class ..._BoundArgs, class _TupleUj>
+struct _is_valid_bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj>
+{
+ static const bool value = __invokable<_Fp,
+ typename __mu_return<_BoundArgs, _TupleUj>::type...>::value;
+};
+
+template <class _Fp, class ..._BoundArgs, class _TupleUj>
+struct _is_valid_bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj>
+{
+ static const bool value = __invokable<_Fp,
+ typename __mu_return<const _BoundArgs, _TupleUj>::type...>::value;
+};
+
+template <class _Fp, class _BoundArgs, class _TupleUj,
+ bool = _is_valid_bind_return<_Fp, _BoundArgs, _TupleUj>::value>
struct __bind_return;
template <class _Fp, class ..._BoundArgs, class _TupleUj>
-struct __bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj>
+struct __bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj, true>
{
typedef typename __invoke_of
<
## -1647,7 +1669,7 ##
};
template <class _Fp, class ..._BoundArgs, class _TupleUj>
-struct __bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj>
+struct __bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj, true>
{
typedef typename __invoke_of
<
## -1673,8 +1695,10 ##
class __bind
: public __weak_result_type<typename decay<_Fp>::type>
{
+protected:
typedef typename decay<_Fp>::type _Fd;
typedef tuple<typename decay<_BoundArgs>::type...> _Td;
+private:
_Fd __f_;
_Td __bound_args_;
## -1731,7 +1755,7 ##
template <class ..._Args>
_LIBCPP_INLINE_VISIBILITY
- typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type
+ typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type
operator()(_Args&& ...__args) const
{
return __apply_functor(__f_, __bound_args_, __indices(),
## -1747,6 +1771,8 ##
: public __bind<_Fp, _BoundArgs...>
{
typedef __bind<_Fp, _BoundArgs...> base;
+ typedef typename base::_Fd _Fd;
+ typedef typename base::_Td _Td;
public:
typedef _Rp result_type;
## -1784,7 +1810,12 ##
template <class ..._Args>
_LIBCPP_INLINE_VISIBILITY
- result_type
+ typename enable_if
+ <
+ is_convertible<typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type,
+ result_type>::value,
+ result_type
+ >::type
operator()(_Args&& ...__args)
{
return base::operator()(_VSTD::forward<_Args>(__args)...);
## -1792,7 +1823,12 ##
template <class ..._Args>
_LIBCPP_INLINE_VISIBILITY
- result_type
+ typename enable_if
+ <
+ is_convertible<typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type,
+ result_type>::value,
+ result_type
+ >::type
operator()(_Args&& ...__args) const
{
return base::operator()(_VSTD::forward<_Args>(__args)...);
It works on Ubuntu (listdc++ instead of libc++) with clang 3.2, so it's not issue in your code.

Resources