Random access of boost::transformed_range via boost::any_range - c++11
I'm trying to use boost::any_range (with random access tag) in some legacy code, but found that it does not like lambdas. Compilation error seems to complain about the lack of default constructor for lambda objects. Is this expected behavior? Is it by design? I'm on MSVC C++17 with boost version 1.66.
Documentation mentions that transformed_range has the same category as input range:
https://www.boost.org/doc/libs/1_66_0/libs/range/doc/html/range/reference/adaptors/reference/transformed.html
The problem is obviously in somewhere in boost::any_range, because if I just use auto, it works (cf rngneg_auto below)
#include <boost/range/adaptor/transformed.hpp>
#include <boost/range/any_range.hpp>
#include <iostream>
#include <vector>
using boost::adaptors::transformed;
using double_range = boost::any_range<const double
, boost::random_access_traversal_tag
, const double>;
struct negate
{
constexpr double operator() (const double x) const
{
return -x;
}
};
int main(int argc, char** argv)
{
const std::vector<double> v{ 1.0, 2.0, 3.0 };
// this works
const auto rngneg_auto = v | transformed([](double x) { return -x; });
std::cout << "Second element is " << rngneg_auto[1] << std::endl;
// ... and this
const double_range rngneg = v | transformed(negate());
std::cout << "Second element is " << rngneg[1] << std::endl;
#if 0
// but not that
const double_range rngneg_lambda = v | transformed([](double x) { return -x; });
std::cout << "Second element is " << rngneg_lambda[1] << std::endl;
#endif
return 0;
}
For the first two cases, the program prints
Second element is -2
Second element is -2
Third is a compilation error (I think it's because lambdas aren't default-constructible):
1>\boost.org\boost\1.66.0\include\boost\optional\optional.hpp(733): error C2280: 'main::<lambda_6f21fa0f6ab2ea01b2b99a85be3eab65> &main::<lambda_6f21fa0f6ab2ea01b2b99a85be3eab65>::operator =(const main::<lambda_6f21fa0f6ab2ea01b2b99a85be3eab65> &)': attempting to reference a deleted function
1> ***: note: see declaration of 'main::<lambda_6f21fa0f6ab2ea01b2b99a85be3eab65>::operator ='
1>\boost.org\boost\1.66.0\include\boost\optional\optional.hpp(733): note: while compiling class template member function 'void boost::optional_detail::optional_base<T>::assign_value(main::<lambda_6f21fa0f6ab2ea01b2b99a85be3eab65> &&)'
1> with
1> [
1> T=main::<lambda_6f21fa0f6ab2ea01b2b99a85be3eab65>
1> ]
1>\boost.org\boost\1.66.0\include\boost\optional\optional.hpp(262): note: see reference to function template instantiation 'void boost::optional_detail::optional_base<T>::assign_value(main::<lambda_6f21fa0f6ab2ea01b2b99a85be3eab65> &&)' being compiled
1> with
1> [
1> T=main::<lambda_6f21fa0f6ab2ea01b2b99a85be3eab65>
1> ]
1>\boost.org\boost\1.66.0\include\boost\optional\optional.hpp(831): note: see reference to class template instantiation 'boost::optional_detail::optional_base<T>' being compiled
1> with
1> [
1> T=main::<lambda_6f21fa0f6ab2ea01b2b99a85be3eab65>
1> ]
1>\boost.org\boost\1.66.0\include\boost\range\detail\default_constructible_unary_fn.hpp(48): note: see reference to class template instantiation 'boost::optional<F>' being compiled
1> with
1> [
1> F=main::<lambda_6f21fa0f6ab2ea01b2b99a85be3eab65>
1> ]
1>\boost.org\boost\1.66.0\include\boost\utility\detail\result_of_iterate.hpp(70): note: see reference to class template instantiation 'boost::range_detail::default_constructible_unary_fn_wrapper<F,R>' being compiled
1> with
1> [
1> F=main::<lambda_6f21fa0f6ab2ea01b2b99a85be3eab65>,
1> R=double
1> ]
1>\boost.org\boost\1.66.0\include\boost\utility\detail\result_of_iterate.hpp(43): note: see reference to class template instantiation 'boost::detail::cpp0x_result_of<F (T0)>' being compiled
1> with
1> [
1> F=const boost::range_detail::default_constructible_unary_fn_wrapper<main::<lambda_6f21fa0f6ab2ea01b2b99a85be3eab65>,double> &,
1> T0=const double &
1> ]
1>\boost.org\boost\1.66.0\include\boost\mpl\eval_if.hpp(41): note: see reference to class template instantiation 'boost::result_of<const UnaryFunc &(const double &)>' being compiled
1> with
1> [
1> UnaryFunc=boost::range_detail::default_constructible_unary_fn_wrapper<main::<lambda_6f21fa0f6ab2ea01b2b99a85be3eab65>,double>
1> ]
1>\boost.org\boost\1.66.0\include\boost\iterator\iterator_adaptor.hpp(154): note: see reference to class template instantiation 'boost::mpl::eval_if<boost::is_same<T,boost::iterators::use_default>,DefaultNullaryFn,boost::mpl::identity<T>>' being compiled
1> with
1> [
1> T=boost::iterators::use_default,
1> DefaultNullaryFn=boost::result_of<const boost::range_detail::default_constructible_unary_fn_wrapper<main::<lambda_6f21fa0f6ab2ea01b2b99a85be3eab65>,double> &(const double &)>
1> ]
1>\boost.org\boost\1.66.0\include\boost\iterator\transform_iterator.hpp(55): note: see reference to class template instantiation 'boost::iterators::detail::ia_dflt_help<Reference,boost::result_of<const UnaryFunc &(const double &)>>' being compiled
1> with
1> [
1> Reference=boost::iterators::use_default,
1> UnaryFunc=boost::range_detail::default_constructible_unary_fn_wrapper<main::<lambda_6f21fa0f6ab2ea01b2b99a85be3eab65>,double>
1> ]
1>\boost.org\boost\1.66.0\include\boost\iterator\transform_iterator.hpp(81): note: see reference to class template instantiation 'boost::iterators::detail::transform_iterator_base<UnaryFunc,Iterator,Reference,Value>' being compiled
1> with
1> [
1> UnaryFunc=boost::range_detail::default_constructible_unary_fn_wrapper<main::<lambda_6f21fa0f6ab2ea01b2b99a85be3eab65>,double>,
1> Iterator=std::_Vector_const_iterator<std::_Vector_val<std::_Simple_types<double>>>,
1> Reference=boost::iterators::use_default,
1> Value=boost::iterators::use_default
1> ]
1>c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.14.26428\include\xutility(652): note: see reference to class template instantiation 'boost::iterators::transform_iterator<boost::range_detail::default_constructible_unary_fn_wrapper<F,R>,It,boost::iterators::use_default,boost::iterators::use_default>' being compiled
1> with
1> [
1> F=main::<lambda_6f21fa0f6ab2ea01b2b99a85be3eab65>,
1> R=double,
1> It=std::_Vector_const_iterator<std::_Vector_val<std::_Simple_types<double>>>
1> ]
1>\boost.org\boost\1.66.0\include\boost\iterator\iterator_categories.hpp(120): note: see reference to class template instantiation 'std::iterator_traits<Iterator>' being compiled
1> with
1> [
1> Iterator=boost::iterators::transform_iterator<boost::range_detail::default_constructible_unary_fn_wrapper<main::<lambda_6f21fa0f6ab2ea01b2b99a85be3eab65>,double>,std::_Vector_const_iterator<std::_Vector_val<std::_Simple_types<double>>>,boost::iterators::use_default,boost::iterators::use_default>
1> ]
1>\boost.org\boost\1.66.0\include\boost\range\iterator_range_core.hpp(156): note: see reference to class template instantiation 'boost::iterators::iterator_traversal<IteratorT>' being compiled
1> with
1> [
1> IteratorT=boost::iterators::transform_iterator<boost::range_detail::default_constructible_unary_fn_wrapper<main::<lambda_6f21fa0f6ab2ea01b2b99a85be3eab65>,double>,std::_Vector_const_iterator<std::_Vector_val<std::_Simple_types<double>>>,boost::iterators::use_default,boost::iterators::use_default>
1> ]
1>\boost.org\boost\1.66.0\include\boost\range\iterator_range_core.hpp(436): note: see reference to class template instantiation 'boost::iterator_range_detail::pure_iterator_traversal<IteratorT>' being compiled
1> with
1> [
1> IteratorT=boost::iterators::transform_iterator<boost::range_detail::default_constructible_unary_fn_wrapper<main::<lambda_6f21fa0f6ab2ea01b2b99a85be3eab65>,double>,std::_Vector_const_iterator<std::_Vector_val<std::_Simple_types<double>>>,boost::iterators::use_default,boost::iterators::use_default>
1> ]
1>\boost.org\boost\1.66.0\include\boost\range\adaptor\transformed.hpp(44): note: see reference to class template instantiation 'boost::iterator_range<boost::iterators::transform_iterator<boost::range_detail::default_constructible_unary_fn_wrapper<F,R>,It,boost::iterators::use_default,boost::iterators::use_default>>' being compiled
1> with
1> [
1> F=main::<lambda_6f21fa0f6ab2ea01b2b99a85be3eab65>,
1> R=double,
1> It=std::_Vector_const_iterator<std::_Vector_val<std::_Simple_types<double>>>
1> ]
1>***: note: see reference to class template instantiation 'boost::range_detail::transformed_range<main::<lambda_6f21fa0f6ab2ea01b2b99a85be3eab65>,const std::vector<double,std::allocator<_Ty>>>' being compiled
1> with
1> [
1> _Ty=double
1> ]
1>***: note: 'main::<lambda_6f21fa0f6ab2ea01b2b99a85be3eab65> &main::<lambda_6f21fa0f6ab2ea01b2b99a85be3eab65>::operator =(const main::<lambda_6f21fa0f6ab2ea01b2b99a85be3eab65> &)': function was explicitly deleted
It's choking because it's trying to figure out how to construct the any_range from the transformed_range and thinks the lambda is a default constructible type. I haven't looked deeply into why but I imagine this is because there's nothing explicitly saying that it isn't and the lambda's type is unique. Of course it's meaningless to try to default construct the lambda's type.
I'd say the simplest way to make it work is to use a type where it's clear (through standard templates) that it can't be default constructed, ie std::function<>. This compiles:
const double_range rngneg_lambda = v | transformed(static_cast<std::function<double(double)>>([](double x) { return -x; }));
Related
'boost::detail::variant::visitation_impl': none of the 2 overloads could convert all the argument types
I'm not able to build two of my projects with Boost libraries 1.61.0 and Visual Studio 2015 Update 3. These projects used to build fine for years with various combinations of Visual Studio and Boost versions, and I didn't change anything in my code except from updating Visual Studio and Boost libraries. The error I get with both of these projects is: 'boost::detail::variant::visitation_impl': none of the 2 overloads could convert all the argument types In both of these projects I don't use boost::variant directly from my code. In one case it looks like boost::variant is being used from boost::signals2 (which I also don't use directly from my code) and in the other case it looks like boost::variant is being used from Cpp-Netlib 0.11.2. Here are the relevant parts of the output logs of these two projects: 1>d:\libraries\boost_1_61_0\boost\variant\detail\visitation_impl.hpp(267): error C2665: 'boost::detail::variant::visitation_impl': none of the 2 overloads could convert all the argument types 1> d:\libraries\boost_1_61_0\boost\variant\detail\visitation_impl.hpp(201): note: could be 'void boost::detail::variant::visitation_impl<next_which,next_step,Visitor,VoidPtrCV,NoBackupFlag>(const int,const int,Visitor &,VoidPtrCV,boost::mpl::false_,NoBackupFlag,Which *,step0 *)' 1> with 1> [ 1> Visitor=boost::detail::variant::destroyer, 1> VoidPtrCV=void *, 1> NoBackupFlag=boost::variant<boost::shared_ptr<void>,boost::signals2::detail::foreign_void_shared_ptr,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_>::has_fallback_type_, 1> Which=next_which, 1> step0=next_step 1> ] 1> d:\libraries\boost_1_61_0\boost\variant\detail\visitation_impl.hpp(183): note: or 'void boost::detail::variant::visitation_impl<next_which,next_step,Visitor,VoidPtrCV,NoBackupFlag>(int,int,Visitor &,VPCV,boost::mpl::true_,NBF,W *,S *)' 1> with 1> [ 1> Visitor=boost::detail::variant::destroyer, 1> VoidPtrCV=void *, 1> NoBackupFlag=boost::variant<boost::shared_ptr<void>,boost::signals2::detail::foreign_void_shared_ptr,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_>::has_fallback_type_, 1> VPCV=void *, 1> NBF=boost::variant<boost::shared_ptr<void>,boost::signals2::detail::foreign_void_shared_ptr,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_>::has_fallback_type_, 1> W=next_which, 1> S=next_step 1> ] 1> d:\libraries\boost_1_61_0\boost\variant\detail\visitation_impl.hpp(267): note: while trying to match the argument list '(const int, const int, boost::detail::variant::destroyer, void *, is_apply_visitor_unrolled, boost::variant<boost::shared_ptr<void>,boost::signals2::detail::foreign_void_shared_ptr,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_>::has_fallback_type_, next_which *, next_step *)' 1> d:\libraries\boost_1_61_0\boost\variant\variant.hpp(2326): note: see reference to function template instantiation 'void boost::detail::variant::visitation_impl<first_which,first_step,Visitor,VoidPtrCV,boost::variant<boost::shared_ptr<void>,boost::signals2::detail::foreign_void_shared_ptr,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_>::has_fallback_type_>(const int,const int,Visitor &,VoidPtrCV,boost::mpl::false_,NoBackupFlag,Which *,step0 *)' being compiled 1> with 1> [ 1> Visitor=boost::detail::variant::destroyer, 1> VoidPtrCV=void *, 1> NoBackupFlag=boost::variant<boost::shared_ptr<void>,boost::signals2::detail::foreign_void_shared_ptr,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_>::has_fallback_type_, 1> Which=first_which, 1> step0=first_step 1> ] 1> d:\libraries\boost_1_61_0\boost\variant\variant.hpp(2337): note: see reference to function template instantiation 'void boost::variant<boost::shared_ptr<void>,boost::signals2::detail::foreign_void_shared_ptr,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_>::internal_apply_visitor_impl<Visitor,void*>(int,int,Visitor &,VoidPtrCV)' being compiled 1> with 1> [ 1> Visitor=boost::detail::variant::destroyer, 1> VoidPtrCV=void * 1> ] 1> d:\libraries\boost_1_61_0\boost\variant\variant.hpp(2335): note: see reference to function template instantiation 'void boost::variant<boost::shared_ptr<void>,boost::signals2::detail::foreign_void_shared_ptr,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_>::internal_apply_visitor_impl<Visitor,void*>(int,int,Visitor &,VoidPtrCV)' being compiled 1> with 1> [ 1> Visitor=boost::detail::variant::destroyer, 1> VoidPtrCV=void * 1> ] 1> d:\libraries\boost_1_61_0\boost\variant\variant.hpp(1345): note: see reference to function template instantiation 'void boost::variant<boost::shared_ptr<void>,boost::signals2::detail::foreign_void_shared_ptr,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_>::internal_apply_visitor<boost::detail::variant::destroyer>(Visitor &)' being compiled 1> with 1> [ 1> Visitor=boost::detail::variant::destroyer 1> ] 1> d:\libraries\boost_1_61_0\boost\variant\variant.hpp(1345): note: see reference to function template instantiation 'void boost::variant<boost::shared_ptr<void>,boost::signals2::detail::foreign_void_shared_ptr,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_>::internal_apply_visitor<boost::detail::variant::destroyer>(Visitor &)' being compiled 1> with 1> [ 1> Visitor=boost::detail::variant::destroyer 1> ] 1> d:\libraries\boost_1_61_0\boost\variant\variant.hpp(1343): note: while compiling class template member function 'void boost::variant<boost::shared_ptr<void>,boost::signals2::detail::foreign_void_shared_ptr,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_>::destroy_content(void) noexcept' 1> d:\libraries\boost_1_61_0\boost\variant\variant.hpp(1352): note: see reference to function template instantiation 'void boost::variant<boost::shared_ptr<void>,boost::signals2::detail::foreign_void_shared_ptr,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_>::destroy_content(void) noexcept' being compiled 1> d:\libraries\boost_1_61_0\boost\signals2\slot_base.hpp(47): note: see reference to class template instantiation 'boost::variant<boost::shared_ptr<void>,boost::signals2::detail::foreign_void_shared_ptr,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_>' being compiled 1>d:\libraries\boost_1_61_0\boost\variant\detail\visitation_impl.hpp(267): error C2665: 'boost::detail::variant::visitation_impl': none of the 2 overloads could convert all the argument types 1> d:\libraries\boost_1_61_0\boost\variant\detail\visitation_impl.hpp(201): note: could be 'void boost::detail::variant::visitation_impl<next_which,next_step,Visitor,VoidPtrCV,NoBackupFlag>(const int,const int,Visitor &,VoidPtrCV,boost::mpl::false_,NoBackupFlag,Which *,step0 *)' 1> with 1> [ 1> Visitor=boost::detail::variant::copy_into, 1> VoidPtrCV=const void *, 1> NoBackupFlag=boost::variant<uint16_t,boost::shared_future<uint16_t>,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_>::has_fallback_type_, 1> Which=next_which, 1> step0=next_step 1> ] 1> d:\libraries\boost_1_61_0\boost\variant\detail\visitation_impl.hpp(183): note: or 'void boost::detail::variant::visitation_impl<next_which,next_step,Visitor,VoidPtrCV,NoBackupFlag>(int,int,Visitor &,VPCV,boost::mpl::true_,NBF,W *,S *)' 1> with 1> [ 1> Visitor=boost::detail::variant::copy_into, 1> VoidPtrCV=const void *, 1> NoBackupFlag=boost::variant<uint16_t,boost::shared_future<uint16_t>,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_>::has_fallback_type_, 1> VPCV=const void *, 1> NBF=boost::variant<uint16_t,boost::shared_future<uint16_t>,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_>::has_fallback_type_, 1> W=next_which, 1> S=next_step 1> ] 1> d:\libraries\boost_1_61_0\boost\variant\detail\visitation_impl.hpp(267): note: while trying to match the argument list '(const int, const int, boost::detail::variant::copy_into, const void *, is_apply_visitor_unrolled, boost::variant<uint16_t,boost::shared_future<uint16_t>,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_>::has_fallback_type_, next_which *, next_step *)' 1> d:\libraries\boost_1_61_0\boost\variant\variant.hpp(2326): note: see reference to function template instantiation 'void boost::detail::variant::visitation_impl<first_which,first_step,Visitor,VoidPtrCV,boost::variant<uint16_t,boost::shared_future<uint16_t>,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_>::has_fallback_type_>(const int,const int,Visitor &,VoidPtrCV,boost::mpl::false_,NoBackupFlag,Which *,step0 *)' being compiled 1> with 1> [ 1> Visitor=boost::detail::variant::copy_into, 1> VoidPtrCV=const void *, 1> NoBackupFlag=boost::variant<uint16_t,boost::shared_future<uint16_t>,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_>::has_fallback_type_, 1> Which=first_which, 1> step0=first_step 1> ] 1> d:\libraries\boost_1_61_0\boost\variant\variant.hpp(2348): note: see reference to function template instantiation 'void boost::variant<uint16_t,boost::shared_future<uint16_t>,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_>::internal_apply_visitor_impl<Visitor,const void*>(int,int,Visitor &,VoidPtrCV)' being compiled 1> with 1> [ 1> Visitor=boost::detail::variant::copy_into, 1> VoidPtrCV=const void * 1> ] 1> d:\libraries\boost_1_61_0\boost\variant\variant.hpp(2346): note: see reference to function template instantiation 'void boost::variant<uint16_t,boost::shared_future<uint16_t>,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_>::internal_apply_visitor_impl<Visitor,const void*>(int,int,Visitor &,VoidPtrCV)' being compiled 1> with 1> [ 1> Visitor=boost::detail::variant::copy_into, 1> VoidPtrCV=const void * 1> ] 1> d:\libraries\boost_1_61_0\boost\variant\variant.hpp(1746): note: see reference to function template instantiation 'void boost::variant<uint16_t,boost::shared_future<uint16_t>,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_>::internal_apply_visitor<boost::detail::variant::copy_into>(Visitor &) const' being compiled 1> with 1> [ 1> Visitor=boost::detail::variant::copy_into 1> ] 1> d:\libraries\boost_1_61_0\boost\variant\variant.hpp(1746): note: see reference to function template instantiation 'void boost::variant<uint16_t,boost::shared_future<uint16_t>,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_>::internal_apply_visitor<boost::detail::variant::copy_into>(Visitor &) const' being compiled 1> with 1> [ 1> Visitor=boost::detail::variant::copy_into 1> ] 1> d:\libraries\boost_1_61_0\boost\variant\variant.hpp(1742): note: while compiling class template member function 'boost::variant<uint16_t,boost::shared_future<uint16_t>,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_>::variant(const boost::variant<uint16_t,boost::shared_future<uint16_t>,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_> &)' 1> d:\libraries\cpp-netlib-0.11.2-final\build\install\include\boost\network\protocol\http\message\directives\status.hpp(36): note: see reference to function template instantiation 'boost::variant<uint16_t,boost::shared_future<uint16_t>,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_>::variant(const boost::variant<uint16_t,boost::shared_future<uint16_t>,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_> &)' being compiled 1> d:\libraries\cpp-netlib-0.11.2-final\build\install\include\boost\network\protocol\http\message\directives\status.hpp(29): note: see reference to class template instantiation 'boost::variant<uint16_t,boost::shared_future<uint16_t>,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_,boost::detail::variant::void_>' being compiled Is this a bug in the boost libraries?
It sounds like you have a broken Boost installation. Are you keeping multiple versions of Boost laying around? There are multiple examples of Boost 1.61.0 and Visual Studio 2015 update 3 working together successfully on the web, though this one does say there are some issues with the new SFINAE feature. Try removing old Boost installations and make a clean install of Boost 1.61.0 from the Boost distribution. It is also possible that Visual Studio was corrupted during the install or update, but I have seen fewer of those types of problems.
c++ 11 include inside #ifdef
In my Visual studio 2012 ,C++11 static function I have: kuku* kuku::createKuku(bool enable, std::string dumpPat) { #ifndef ANDROID #include "kukuWin.h" return new kukuWin(enable, dumpPat); #else #include "kukuAndroid.h" return new kukuAndroid(enable, dumpPat); #endif } in c++98 it works , but here I have multiple errors: 1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\excpt.h(29): error : linkage specification is not allowed 1> extern "C" { 1> ^ 1> 1>C:\Program Files (x86)\Windows Kits\8.0\Include\shared\windef.h(17): error : linkage specification is not allowed 1> extern "C" { 1> ^ 1> 1>C:\Program Files (x86)\Windows Kits\8.0\Include\shared\specstrings.h(49): error : linkage specification is not allowed 1> extern "C" { 1> ^ 1> 1>C:\Program Files (x86)\Windows Kits\8.0\Include\shared\driverspecs.h(133): error : linkage specification is not allowed 1> extern "C" { 1> ^ 1> 1>C:\Program Files (x86)\Windows Kits\8.0\Include\shared\minwindef.h(42): error : linkage specification is not allowed 1> extern "C" { 1> ^ :) Can anyone help me with it, Thanks
An #include directive will put the full text of the included file exactly where the directive is. So all that stuff in "kukuWin.h" is going smack dab in the middle of your createKuku function, where it doesn't belong. You'll almost always put inclusions at the top of your source files.
Compiling issue with VS2010 and boost::posix_time
I've run into a problem driving me mad. I've implemented a timer using the followin timer entry construct: typedef std::multimap<boost::posix_time::ptime, events::ITimeout*> TEntryMap; TEntryMap entries_; and I insert elements into the multimap with: boost::posix_time::ptime tTimeout = boost::posix_time::microsec_clock::local_time() + boost::posix_time::milliseconds(timeout); entries_.insert(std::make_pair(tTimeout, ptr)); // ptr is the events::ITimeout object and in one translation unit (cpp file) it works perfectly. However, now I need to move this functionality to another cpp file, and now I get a compilation error: 1>Build started 2013-02-07 15:38:18. 1>ClCompile: 1> EventDispatcher.cpp 1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\utility(260): error C2678: binary '=' : no operator found which takes a left-hand operand of type 'const boost::posix_time::ptime' (or there is no acceptable conversion) 1> ....\boost\boost\date_time\posix_time\ptime.hpp(57): could be 'boost::posix_time::ptime &boost::posix_time::ptime::operator =(const boost::posix_time::ptime &)' 1> while trying to match the argument list '(const boost::posix_time::ptime, const boost::posix_time::ptime)' 1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\utility(259) : while compiling class template member function 'std::pair<_Ty1,_Ty2> &std::pair<_Ty1,_Ty2>::operator =(std::pair<_Ty1,_Ty2> &&)' 1> with 1> [ 1> _Ty1=const boost::posix_time::ptime, 1> _Ty2=events::ITimeout * 1> ] 1> ....\eventdispatcher.cpp(72) : see reference to class template instantiation 'std::pair<_Ty1,_Ty2>' being compiled 1> with 1> [ 1> _Ty1=const boost::posix_time::ptime, 1> _Ty2=events::ITimeout * 1> ] 1> I'm clueless and been struggling with this for 2 hours. I see no difference between the working implementation, and the non-working one. The same construct, same multimap, same includes, same everything! ;(
I found the cause of the problem, and it smells like a VS2010 C++ compiler bug (when using std::remove_if). In a function implementation later on in the class using the construct, I tried to remove elements in the map with: void removeEntry(events::ITimeout* p) { std::remove_if(entries_.begin(), entries_.end(), [&](TEntryMap::value_type& entry)->bool { return (entry.second == p); } ); } Changing that code to: void removeEntry(events::ITimeout* p) { TEntryMap::iterator it = std::find_if(entries_.begin(), entries_.end(), [&](TEntryMap::value_type& entry)->bool { return (entry.second == p); } ); if (it != entries_.end()) entries_.erase(it); } makes the insertion code work. Go figure. Note that even if I use a struct based predicate instead of a lambda closure, it still doesn't work with std::remove_if...
This use of std::make_pair works fine in GCC 3 and 4. It fails in Visual Studio C++ 2010. Why?
This compiles fine in GCC 3 and 4. MSVC++ can't figure out the type of noFunction and throws some hideous errors. Note if you cast noFunction to BFunction, it works just fine in VS2010. My question: is this a defect in VS2010, or GCC bending the rules? #include <map> using namespace std; typedef bool (*AFunction)(int arg1, int arg2); typedef bool (*BFunction)(long arg1, bool arg2); bool noFunction(long, bool) { return true; } void test(AFunction a) { make_pair(a, noFunction); //fails in VS2010 } N.B. casting noFunction to BFunction fixes the problem in VS2010. make_pair(a, (BFunction)noFunction); //works everywhere . . . Here is the error for reference: 1> makepairtest.cpp 1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\type_traits(197): error C2752: 'std::tr1::_Remove_reference<_Ty>' : more than one partial specialization matches the template argument list 1> with 1> [ 1> _Ty=bool (__cdecl &)(long,bool) 1> ] 1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\xtr1common(356): could be 'std::tr1::_Remove_reference<_Ty&&>' 1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\xtr1common(350): or 'std::tr1::_Remove_reference<_Ty&>' 1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\type_traits(962) : see reference to class template instantiation 'std::tr1::remove_reference<_Ty>' being compiled 1> with 1> [ 1> _Ty=bool (__cdecl &)(long,bool) 1> ] 1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\utility(26) : see reference to class template instantiation 'std::tr1::decay<_Ty>' being compiled 1> with 1> [ 1> _Ty=bool (__cdecl &)(long,bool) 1> ] 1> c:\xxx\makepairtest.cpp(14) : see reference to class template instantiation 'std::tr1::_Unrefwrap<_Type>' being compiled 1> with 1> [ 1> _Type=bool (__cdecl &)(long,bool) 1> ] 1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\type_traits(965): error C2528: 'abstract declarator' : pointer to reference is illegal 1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\type_traits(349): error C2528: 'type' : pointer to reference is illegal 1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\type_traits(967) : see reference to class template instantiation 'std::tr1::add_pointer<_Ty>' being compiled 1> with 1> [ 1> _Ty=bool (__cdecl &)(long,bool) 1> ] 1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\utility(148): error C2535: 'std::_Pair_base<_Ty1,_Ty2>::_Pair_base(const _Ty1 &,const _Ty2)' : member function already defined or declared 1> with 1> [ 1> _Ty1=bool (__cdecl *)(int,int), 1> _Ty2=bool (__cdecl &)(long,bool) 1> ] 1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\utility(134) : see declaration of 'std::_Pair_base<_Ty1,_Ty2>::_Pair_base' 1> with 1> [ 1> _Ty1=bool (__cdecl *)(int,int), 1> _Ty2=bool (__cdecl &)(long,bool) 1> ] 1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\utility(174) : see reference to class template instantiation 'std::_Pair_base<_Ty1,_Ty2>' being compiled 1> with 1> [ 1> _Ty1=bool (__cdecl *)(int,int), 1> _Ty2=bool (__cdecl &)(long,bool) 1> ] 1> c:\xxx\makepairtest.cpp(14) : see reference to class template instantiation 'std::pair<_Ty1,_Ty2>' being compiled 1> with 1> [ 1> _Ty1=bool (__cdecl *)(int,int), 1> _Ty2=bool (__cdecl &)(long,bool) 1> ]
Taking the address of noFunction works with VC10 and gcc 4.5.2, i.e.: make_pair(a, &noFunction); Per the error message you posted, I would guess it has to do with how VC handles binding to rvalues.
"My question: is this a defect in VS2010, or GCC bending the rules?" When in doubt blame Visual C++ and/or Bill Gates. Note that there is a difference between the value of noFunction when used in your code and the type defined by BFunction. noFunction will be a reference to a function whereas BFunction defines a pointer to a function. It is a bit hard to explain but it might help to contemplate the following program. #include <iostream> #include <typeinfo> bool noFunction(long, bool) { return true; } typedef bool (function_ref)(long, bool); typedef bool (*function_ptr)(long, bool); int main() { std::cout << typeid(noFunction).name() << '\n'; std::cout << typeid(&noFunction).name() << '\n'; std::cout << typeid(function_ref).name() << '\n'; std::cout << typeid(function_ptr).name() << '\n'; return 0; } It seems that Visual C++ is choking on function references. I'm not sure if there is a legitimate reason why it would reject that but I would expect that you should be able to construct a pair with types that are a model of copy constructable. Eg you should be able construct but not assign std::pair<int, int const&>.
time_point modulo duration does not compile
Env: win7, visual 2013 x64 Given a std::chrono::system_clock::time_point tp , and a std::chrono::system_clock::duration dur , how to find the next std::chrono::system_clock::time_point tp2 following : tp2 = tp - tp % dur + dur This represents the next time point considering a clock and a heartbeat, for example dur=10s. I tryied a lot ... my best I guess was this: using namespace std; // for better readability template < class duration_t > system_clock::time_point next_time_aligned_on(const system_clock::time_point & tp, const duration_t & step) { const system_clock::duration d = tp.time_since_epoch(); const auto step2 = duration_cast<system_clock::duration>(step); const auto elapsed_since_last = d % step2; return tp - elapsed_since_last + step; } I got always the same compilation error: 1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC \include\type_traits(1446): error C2446: ':' : no conversion from 'std::chrono::duration<std::chrono::system_clock::rep,std::chrono::system_clock::period>' to 'std::chrono::system_clock::rep' 1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called 1> C:\trading\tepp\src\tepp/tools/strings.h(49) : see reference to class template instantiation std::common_type<std::chrono::system_clock::rep,std::chrono::duration<std::chrono::system_clock::rep,std::chrono::system_clock::period>>' being compiled 1> st_gammalong.cpp(30) : see reference to function template instantiation 'std::chrono::system_clock::time_point tepp::next_time_aligned_on<std::chrono::seconds>(const std::chrono::system_clock::time_point &,const duration_t &)' being compiled 1> with 1> [ 1> duration_t=std::chrono::seconds 1> ] My question: how to use modulo operator in c++11 std::chrono ?