Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/141.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 带lambda的Boost算法无法编译_C++_C++11_Boost_Lambda - Fatal编程技术网

C++ 带lambda的Boost算法无法编译

C++ 带lambda的Boost算法无法编译,c++,c++11,boost,lambda,C++,C++11,Boost,Lambda,以下示例代码: #define BOOST_RESULT_OF_USE_DECLTYPE // does not help #include <vector> #include <algorithm> #include <future> #include <boost/range/algorithm.hpp> struct DW { std::promise<bool> success_; }; template <

以下示例代码:

#define BOOST_RESULT_OF_USE_DECLTYPE // does not help

#include <vector>
#include <algorithm>
#include <future>
#include <boost/range/algorithm.hpp>

struct DW {
    std::promise<bool> success_;
};

template <class T>
class Pool
{
public:
    Pool() : container_{}
    {};
public:
    typename std::vector<T>::iterator begin() { return container_.begin(); }
    typename std::vector<T>::iterator end()   { return container_.end(); }
    typename std::vector<T>::const_iterator begin() const { return container_.begin(); }
    typename std::vector<T>::const_iterator end()   const { return container_.end(); }
private:
    std::vector<T>     container_;     ///< holder of elements
};

#define LAMBDA [] (DW& w) { return w.success_.get_future().get(); }

int main()
{
    Pool<DW> vec;

    auto s = std::count_if(vec.begin(), vec.end(), LAMBDA);
    auto b = boost::count_if(vec, LAMBDA);

    return (s == b) ? 0 : 1;
}
\u USE\u DECLTYPE//的定义BOOST\u RESULT\u没有帮助
#包括
#包括
#包括
#包括
结构数据仓库{
std:承诺成功;
};
模板
班级池
{
公众:
池():容器{}
{};
公众:
typename std::vector::迭代器begin(){return container_uz.begin();}
typename std::vector::迭代器end(){return container_uuz.end();}
typename std::vector::const_迭代器begin()const{return container_uu.begin();}
typename std::vector::const_迭代器end()const{return container_uu.end();}
私人:
std::向量容器;//<元素的持有者
};
#定义LAMBDA[](DW&w){return w.success_.get_future().get();}
int main()
{
池vec;
auto s=std::count_if(vec.begin()、vec.end()、LAMBDA);
自动b=boost::计数(向量,λ);
回报率(s==b)?0:1;
}
未能按照GCC 4.8.5、6.2或8进行编译:

g++ -g -pthread -std=gnu++0x -Wall -pedantic -Wextra -Wformat=2 -o "ranger" "ranger.cpp" (in directory: /tmp)
In file included from /usr/local/include/boost/iterator/iterator_categories.hpp:15:0,
                 from /usr/local/include/boost/iterator/iterator_concepts.hpp:10,
                 from /usr/local/include/boost/range/concepts.hpp:20,
                 from /usr/local/include/boost/range/algorithm.hpp:29,
                 from ranger.cpp:6:
/usr/local/include/boost/mpl/eval_if.hpp: In instantiation of ‘struct boost::mpl::eval_if_c<false, boost::range_const_iterator<Pool<DW>, void>, boost::range_mutable_iterator<Pool<DW>, void> >’:
/usr/local/include/boost/range/iterator.hpp:69:17:   required from ‘struct boost::range_iterator<Pool<DW>, void>’
/usr/local/include/boost/range/difference_type.hpp:26:12:   required from ‘struct boost::range_difference<Pool<DW> >’
/usr/local/include/boost/range/algorithm/count_if.hpp:32:1:   required by substitution of ‘template<class SinglePassRange, class UnaryPredicate> typename boost::range_difference<T>::type boost::range::count_if(SinglePassRange&, UnaryPredicate) [with SinglePassRange = Pool<DW>; UnaryPredicate = main()::__lambda5]’
ranger.cpp:34:41:   required from here
/usr/local/include/boost/mpl/eval_if.hpp:60:31: error: no type named ‘type’ in ‘boost::mpl::eval_if_c<false, boost::range_const_iterator<Pool<DW>, void>, boost::range_mutable_iterator<Pool<DW>, void> >::f_ {aka struct boost::range_mutable_iterator<Pool<DW>, void>}’
     typedef typename f_::type type;
                               ^
/usr/local/include/boost/mpl/eval_if.hpp: In instantiation of ‘struct boost::mpl::eval_if_c<true, boost::range_const_iterator<Pool<DW>, void>, boost::range_mutable_iterator<const Pool<DW>, void> >’:
/usr/local/include/boost/range/iterator.hpp:69:17:   required from ‘struct boost::range_iterator<const Pool<DW>, void>’
/usr/local/include/boost/range/difference_type.hpp:26:12:   required from ‘struct boost::range_difference<const Pool<DW> >’
/usr/local/include/boost/range/algorithm/count_if.hpp:41:1:   required by substitution of ‘template<class SinglePassRange, class UnaryPredicate> typename boost::range_difference<const SinglePassRange>::type boost::range::count_if(const SinglePassRange&, UnaryPredicate) [with SinglePassRange = Pool<DW>; UnaryPredicate = main()::__lambda5]’
ranger.cpp:34:41:   required from here
/usr/local/include/boost/mpl/eval_if.hpp:60:31: error: no type named ‘type’ in ‘boost::mpl::eval_if_c<true, boost::range_const_iterator<Pool<DW>, void>, boost::range_mutable_iterator<const Pool<DW>, void> >::f_ {aka struct boost::range_const_iterator<Pool<DW>, void>}’
ranger.cpp: In function ‘int main()’:
ranger.cpp:34:41: error: no matching function for call to ‘count_if(Pool<DW>&, main()::__lambda5)’
     auto b = boost::count_if(vec, LAMBDA);
                                         ^
ranger.cpp:34:41: note: candidates are:
In file included from /usr/local/include/boost/range/algorithm.hpp:40:0,
                 from ranger.cpp:6:
/usr/local/include/boost/range/algorithm/count_if.hpp:41:1: note: template<class SinglePassRange, class UnaryPredicate> typename boost::range_difference<const SinglePassRange>::type boost::range::count_if(const SinglePassRange&, UnaryPredicate)
 count_if(const SinglePassRange& rng, UnaryPredicate pred)
 ^
/usr/local/include/boost/range/algorithm/count_if.hpp:41:1: note:   substitution of deduced template arguments resulted in errors seen above
/usr/local/include/boost/range/algorithm/count_if.hpp:32:1: note: template<class SinglePassRange, class UnaryPredicate> typename boost::range_difference<T>::type boost::range::count_if(SinglePassRange&, UnaryPredicate)
 count_if(SinglePassRange& rng, UnaryPredicate pred)
 ^
/usr/local/include/boost/range/algorithm/count_if.hpp:32:1: note:   substitution of deduced template arguments resulted in errors seen above
Compilation failed.
g++-g-pthread-std=gnu++0x-Wall-pedantic-Wextra-Wformat=2-o“ranger”“ranger.cpp”(在目录:/tmp中)
在/usr/local/include/boost/iterator/iterator_categories.hpp:15:0中包含的文件中,
来自/usr/local/include/boost/iterator/iterator_concepts.hpp:10,
来自/usr/local/include/boost/range/concepts.hpp:20,
来自/usr/local/include/boost/range/algorithm.hpp:29,
来自ranger.cpp:6:
/usr/local/include/boost/mpl/eval_if.hpp:“struct boost::mpl::eval_if_c”的实例化中:
/usr/local/include/boost/range/iterator.hpp:69:17:必须来自“struct boost::range\u iterator”
/usr/local/include/boost/range/difference_type。hpp:26:12:从“struct boost::range_difference”中需要
/usr/local/include/boost/range/algorithm/count_if.hpp:32:1:替换“模板typename boost::range\u difference::type boost::range::count_if(SinglePassRange&,UnaryPredicate)[with SinglePassRange=Pool;UnaryPredicate=main()::\u lambda5]所需
ranger.cpp:34:41:从这里开始需要
/usr/local/include/boost/mpl/eval_if.hpp:60:31:错误:boost::mpl::eval_if_c::f_{aka struct boost::range_mutable_iterator}中没有名为“type”的类型
typedef typename f_u2;::type type;
^
/usr/local/include/boost/mpl/eval_if.hpp:“struct boost::mpl::eval_if_c”的实例化中:
/usr/local/include/boost/range/iterator.hpp:69:17:必须来自“struct boost::range\u iterator”
/usr/local/include/boost/range/difference_type。hpp:26:12:从“struct boost::range_difference”中需要
/usr/local/include/boost/range/algorithm/count_if.hpp:41:1:替换“模板typename boost::range_difference::type boost::range::count_if(const SinglePassRange&,unarydpredicate)[with SinglePassRange=Pool;unarydpredicate=main()
ranger.cpp:34:41:从这里开始需要
/usr/local/include/boost/mpl/eval_if.hpp:60:31:错误:boost::mpl::eval_if_c::f_{aka struct boost::range_const_iterator}中没有名为“type”的类型
ranger.cpp:在函数“int main()”中:
ranger.cpp:34:41:错误:调用“count_if(Pool&,main():_lambda5)”时没有匹配的函数
自动b=boost::计数(向量,λ);
^
ranger.cpp:34:41:注:候选人为:
在/usr/local/include/boost/range/algorithm.hpp:40:0中包含的文件中,
来自ranger.cpp:6:
/usr/local/include/boost/range/algorithm/count\u if.hpp:41:1:注意:模板typename boost::range\u difference::type boost::range::count\u if(常量SinglePassRange&,一元谓词)
计数\u if(常量SinglePassRange&rng,一元谓词pred)
^
/usr/local/include/boost/range/algorithm/count_if.hpp:41:1:注意:替换推导的模板参数会导致上述错误
/usr/local/include/boost/range/algorithm/count\u if.hpp:32:1:注意:模板typename boost::range\u difference::type boost::range::count\u if(SinglePassRange&,UnaryPredicate)
计数\u if(SinglePassRange&rng,一元谓词pred)
^
/usr/local/include/boost/range/algorithm/count_if.hpp:32:1:注意:替换推导的模板参数会导致上述错误
编译失败。
还有叮当声5.0.0(行李箱302784)

$clang++-g-pthread-std=c++14-Wall-pedantic-Wextra-Wformat=2-o“ranger”“ranger.cpp”(在目录:/tmp中)
在ranger.cpp中包含的文件中:6:
在/usr/local/include/boost/range/algorithm.hpp:29中包含的文件中:
在/usr/local/include/boost/range/concepts.hpp:20中包含的文件中:
在/usr/local/include/boost/iterator/iterator_concepts.hpp:10中包含的文件中:
在/usr/local/include/boost/iterator/iterator_categories包含的文件中。hpp:15:
/usr/local/include/boost/mpl/eval_if.hpp:60:26:错误:“boost::range\u mutable\u迭代器”中没有名为“type”的类型
typedef typename f_u2;::type type;
~~~~~~~~~~~~~^~~~
/usr/local/include/boost/range/iterator.hpp:65:31:注意:在模板类“boost::mpl::eval_if_c”的实例化中
typedef typename mpl::eval_if_c<
^
/usr/local/include/boost/range/difference_type.hpp:28:40:注意:在这里请求的模板类“boost::range_iterator”的实例化中
BOOST\u导出的\u类型名范围\u迭代器<
^
/usr/local/include/boost/range/algorithm/count\u if.hpp:31:38:注意:在模板类的实例化中,此处请求“boost::range\u difference”
内联BOOST\u导出的类型BOOST::range\u difference::type
^
ranger.cpp:34:14:注意:在将推导出的模板参数替换为函数模板'count_if'[使用SinglePassRange=Pool,UnaryPredicate=(ranger.cpp:34:35处的lambda)]
自动b=boost::计数(向量,λ);
^
在ranger.cpp中包含的文件中:6:
在/usr/local/include/boost/range/algorithm.hpp:29中包含的文件中:
在/usr/local/include/boost/range/concepts.hpp:20中包含的文件中:
在菲律宾
$ clang++ -g -pthread -std=c++14 -Wall -pedantic -Wextra -Wformat=2  -o "ranger" "ranger.cpp" (in directory: /tmp)
In file included from ranger.cpp:6:
In file included from /usr/local/include/boost/range/algorithm.hpp:29:
In file included from /usr/local/include/boost/range/concepts.hpp:20:
In file included from /usr/local/include/boost/iterator/iterator_concepts.hpp:10:
In file included from /usr/local/include/boost/iterator/iterator_categories.hpp:15:
/usr/local/include/boost/mpl/eval_if.hpp:60:26: error: no type named 'type' in 'boost::range_mutable_iterator<Pool<DW>, void>'
    typedef typename f_::type type;
            ~~~~~~~~~~~~~^~~~
/usr/local/include/boost/range/iterator.hpp:65:31: note: in instantiation of template class 'boost::mpl::eval_if_c<false, boost::range_const_iterator<Pool<DW>, void>, boost::range_mutable_iterator<Pool<DW>, void> >' requested here
        typedef typename mpl::eval_if_c<
                              ^
/usr/local/include/boost/range/difference_type.hpp:28:40: note: in instantiation of template class 'boost::range_iterator<Pool<DW>, void>' requested here
                BOOST_DEDUCED_TYPENAME range_iterator<
                                       ^
/usr/local/include/boost/range/algorithm/count_if.hpp:31:38: note: in instantiation of template class 'boost::range_difference<Pool<DW> >' requested here
inline BOOST_DEDUCED_TYPENAME boost::range_difference<SinglePassRange>::type
                                     ^
ranger.cpp:34:14: note: while substituting deduced template arguments into function template 'count_if' [with SinglePassRange = Pool<DW>, UnaryPredicate = (lambda at ranger.cpp:34:35)]
    auto b = boost::count_if(vec, LAMBDA);
             ^
In file included from ranger.cpp:6:
In file included from /usr/local/include/boost/range/algorithm.hpp:29:
In file included from /usr/local/include/boost/range/concepts.hpp:20:
In file included from /usr/local/include/boost/iterator/iterator_concepts.hpp:10:
In file included from /usr/local/include/boost/iterator/iterator_categories.hpp:15:
/usr/local/include/boost/mpl/eval_if.hpp:60:26: error: no type named 'type' in 'boost::range_const_iterator<Pool<DW>, void>'
    typedef typename f_::type type;
            ~~~~~~~~~~~~~^~~~
/usr/local/include/boost/range/iterator.hpp:65:31: note: in instantiation of template class 'boost::mpl::eval_if_c<true, boost::range_const_iterator<Pool<DW>, void>, boost::range_mutable_iterator<const Pool<DW>, void> >' requested here
        typedef typename mpl::eval_if_c<
                              ^
/usr/local/include/boost/range/difference_type.hpp:28:40: note: in instantiation of template class 'boost::range_iterator<const Pool<DW>, void>' requested here
                BOOST_DEDUCED_TYPENAME range_iterator<
                                       ^
/usr/local/include/boost/range/algorithm/count_if.hpp:40:38: note: in instantiation of template class 'boost::range_difference<const Pool<DW> >' requested here
inline BOOST_DEDUCED_TYPENAME boost::range_difference<const SinglePassRange>::type
                                     ^
ranger.cpp:34:14: note: while substituting deduced template arguments into function template 'count_if' [with SinglePassRange = Pool<DW>, UnaryPredicate = (lambda at ranger.cpp:34:35)]
    auto b = boost::count_if(vec, LAMBDA);
             ^
ranger.cpp:34:14: error: no matching function for call to 'count_if'
    auto b = boost::count_if(vec, LAMBDA);
             ^~~~~~~~~~~~~~~
/usr/local/include/boost/range/algorithm/count_if.hpp:32:1: note: candidate template ignored: substitution failure [with SinglePassRange = Pool<DW>, UnaryPredicate = (lambda at ranger.cpp:34:35)]
count_if(SinglePassRange& rng, UnaryPredicate pred)
^
/usr/local/include/boost/range/algorithm/count_if.hpp:41:1: note: candidate template ignored: substitution failure [with SinglePassRange = Pool<DW>, UnaryPredicate = (lambda at ranger.cpp:34:35)]
count_if(const SinglePassRange& rng, UnaryPredicate pred)
^
3 errors generated.
Compilation failed.
template <class T>
class Pool
{
public:
    Pool() : container_{}
    {};
public:
    using iterator = typename std::vector<T>::iterator;
    using const_iterator = typename std::vector<T>::const_iterator;

    iterator begin() { return container_.begin(); }
    iterator end()   { return container_.end(); }
    const_iterator begin() const { return container_.begin(); }
    const_iterator end()   const { return container_.end(); }
private:
    std::vector<T>     container_;     ///< holder of elements
};