此next_combination代码的用法 [英] Usage of this next_combination code

查看:180
本文介绍了此next_combination代码的用法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我正在尝试从包含一些整数的向量生成组合。现在我想要打印出所有长度为to_generate的组合。
我在 C ++中的组合和排列中找到了此代码使用std :: next_permutation生成组合。 next_combination代码如下:

Currently I am trying to generate combinations from a vector that contains some integers. For now I want it to print out all of the combinations that are of length to_generate. I found this code at combination and permutation in C++ that uses std::next_permutation to generate combinations. The next_combination code is as follows:

template<class RandIt, class Compare>
bool next_combination(RandIt first, RandIt mid, RandIt last, Compare comp)
{
    std::sort(mid, last, std::tr1::bind(comp, std::tr1::placeholders::_2
                                        , std::tr1::placeholders::_1));
    return std::next_permutation(first, last, comp);
}

我试图这样调用:

bool mycomp (int c1, int c2)
{ return (c1)<(c2); }


void test_combos(int to_generate){
    std::vector<int> combo(30);
    for(int i=0;i<30;++i){
        combo.push_back(i);
    }
    while(next_combination<std::vector<int>::iterator,   bool>(combo.begin(),combo.begin()+to_generate,combo.end(),mycomp)){
        for(std::vector<int>::iterator iter = combo.begin(); iter != combo.end() ; ++iter){
            std::cout << *iter << " ";
        }
    }
}

错误消息。

哪些标头可以找到std :: placeholder?

Which headers can I find std::placeholder?

请求,这里是错误消息:

As requested, here is the error message:


$ make
g++ -g -std=c++0x -I /usr/lib/ -c equity.cpp
In file included from /usr/include/c++/4.4/algorithm:62,
                 from misc.hpp:6,
                 from equity.cpp:3:
/usr/include/c++/4.4/bits/stl_algo.h: In function ‘bool std::next_permutation(_BIter, _BIter, _Compare) [with _BIter = __gnu_cxx::__normal_iterator > >, _Compare = bool]’:
misc.hpp:15:   instantiated from ‘bool next_combination(RandIt, RandIt, RandIt, Compare) [with RandIt = __gnu_cxx::__normal_iterator > >, Compare = bool]’
equity.cpp:28:   instantiated from here
/usr/include/c++/4.4/bits/stl_algo.h:3655: error: ‘__comp’ cannot be used as a function
/usr/include/c++/4.4/bits/stl_algo.h:3658: error: ‘__comp’ cannot be used as a function
In file included from /usr/include/c++/4.4/functional:70,
                 from /usr/include/c++/4.4/memory:70,
                 from /usr/include/boost/config/no_tr1/memory.hpp:21,
                 from /usr/include/boost/get_pointer.hpp:12,
                 from /usr/include/boost/bind/mem_fn.hpp:25,
                 from /usr/include/boost/mem_fn.hpp:22,
                 from /usr/include/boost/bind/bind.hpp:26,
                 from /usr/include/boost/bind.hpp:22,
                 from misc.hpp:4,
                 from equity.cpp:3:
/usr/include/c++/4.4/tr1_impl/functional: At global scope:
/usr/include/c++/4.4/tr1_impl/functional: In instantiation of ‘std::_Result_of_impl’:
/usr/include/c++/4.4/tr1_impl/functional:149:   instantiated from ‘std::result_of’
/usr/include/c++/4.4/bits/stl_algo.h:124:   instantiated from ‘const _Tp& std::__median(const _Tp&, const _Tp&, const _Tp&, _Compare) [with _Tp = int, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:2301:   instantiated from ‘void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Size = long int, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:5258:   instantiated from ‘void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’
misc.hpp:13:   instantiated from ‘bool next_combination(RandIt, RandIt, RandIt, Compare) [with RandIt = __gnu_cxx::__normal_iterator > >, Compare = bool]’
equity.cpp:28:   instantiated from here
/usr/include/c++/4.4/tr1_impl/functional:195: error: ‘const volatile bool’ is not a class, struct, or union type
/usr/include/c++/4.4/tr1_impl/functional: In instantiation of ‘std::_Result_of_impl’:
/usr/include/c++/4.4/tr1_impl/functional:149:   instantiated from ‘std::result_of’
/usr/include/c++/4.4/bits/stl_algo.h:124:   instantiated from ‘const _Tp& std::__median(const _Tp&, const _Tp&, const _Tp&, _Compare) [with _Tp = int, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:2301:   instantiated from ‘void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Size = long int, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:5258:   instantiated from ‘void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’
misc.hpp:13:   instantiated from ‘bool next_combination(RandIt, RandIt, RandIt, Compare) [with RandIt = __gnu_cxx::__normal_iterator > >, Compare = bool]’
equity.cpp:28:   instantiated from here
/usr/include/c++/4.4/tr1_impl/functional:195: error: ‘volatile bool’ is not a class, struct, or union type
/usr/include/c++/4.4/tr1_impl/functional: In instantiation of ‘std::_Result_of_impl’:
/usr/include/c++/4.4/tr1_impl/functional:149:   instantiated from ‘std::result_of’
/usr/include/c++/4.4/bits/stl_algo.h:124:   instantiated from ‘const _Tp& std::__median(const _Tp&, const _Tp&, const _Tp&, _Compare) [with _Tp = int, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:2301:   instantiated from ‘void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Size = long int, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:5258:   instantiated from ‘void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’
misc.hpp:13:   instantiated from ‘bool next_combination(RandIt, RandIt, RandIt, Compare) [with RandIt = __gnu_cxx::__normal_iterator > >, Compare = bool]’
equity.cpp:28:   instantiated from here
/usr/include/c++/4.4/tr1_impl/functional:195: error: ‘const bool’ is not a class, struct, or union type
/usr/include/c++/4.4/tr1_impl/functional: In instantiation of ‘std::_Result_of_impl’:
/usr/include/c++/4.4/tr1_impl/functional:149:   instantiated from ‘std::result_of’
/usr/include/c++/4.4/bits/stl_algo.h:124:   instantiated from ‘const _Tp& std::__median(const _Tp&, const _Tp&, const _Tp&, _Compare) [with _Tp = int, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:2301:   instantiated from ‘void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Size = long int, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:5258:   instantiated from ‘void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’
misc.hpp:13:   instantiated from ‘bool next_combination(RandIt, RandIt, RandIt, Compare) [with RandIt = __gnu_cxx::__normal_iterator > >, Compare = bool]’
equity.cpp:28:   instantiated from here
/usr/include/c++/4.4/tr1_impl/functional:195: error: ‘bool’ is not a class, struct, or union type
In file included from /usr/include/c++/4.4/algorithm:62,
                 from misc.hpp:6,
                 from equity.cpp:3:
/usr/include/c++/4.4/bits/stl_algo.h: In function ‘const _Tp& std::__median(const _Tp&, const _Tp&, const _Tp&, _Compare) [with _Tp = int, _Compare = std::_Bind, std::_Placeholder)>]’:
/usr/include/c++/4.4/bits/stl_algo.h:2301:   instantiated from ‘void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Size = long int, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:5258:   instantiated from ‘void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’
misc.hpp:13:   instantiated from ‘bool next_combination(RandIt, RandIt, RandIt, Compare) [with RandIt = __gnu_cxx::__normal_iterator > >, Compare = bool]’
equity.cpp:28:   instantiated from here
/usr/include/c++/4.4/bits/stl_algo.h:124: error: no match for call to ‘(std::_Bind, std::_Placeholder)>) (const int&, const int&)’
/usr/include/c++/4.4/bits/stl_algo.h:125: error: no match for call to ‘(std::_Bind, std::_Placeholder)>) (const int&, const int&)’
/usr/include/c++/4.4/bits/stl_algo.h:127: error: no match for call to ‘(std::_Bind, std::_Placeholder)>) (const int&, const int&)’
/usr/include/c++/4.4/bits/stl_algo.h:131: error: no match for call to ‘(std::_Bind, std::_Placeholder)>) (const int&, const int&)’
/usr/include/c++/4.4/bits/stl_algo.h:133: error: no match for call to ‘(std::_Bind, std::_Placeholder)>) (const int&, const int&)’
In file included from /usr/include/c++/4.4/functional:70,
                 from /usr/include/c++/4.4/memory:70,
                 from /usr/include/boost/config/no_tr1/memory.hpp:21,
                 from /usr/include/boost/get_pointer.hpp:12,
                 from /usr/include/boost/bind/mem_fn.hpp:25,
                 from /usr/include/boost/mem_fn.hpp:22,
                 from /usr/include/boost/bind/bind.hpp:26,
                 from /usr/include/boost/bind.hpp:22,
                 from misc.hpp:4,
                 from equity.cpp:3:
/usr/include/c++/4.4/tr1_impl/functional: At global scope:
/usr/include/c++/4.4/tr1_impl/functional: In instantiation of ‘std::_Result_of_impl’:
/usr/include/c++/4.4/tr1_impl/functional:149:   instantiated from ‘std::result_of’
/usr/include/c++/4.4/bits/stl_algo.h:2230:   instantiated from ‘_RandomAccessIterator std::__unguarded_partition(_RandomAccessIterator, _RandomAccessIterator, _Tp, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Tp = int, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:2301:   instantiated from ‘void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Size = long int, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:5258:   instantiated from ‘void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’
misc.hpp:13:   instantiated from ‘bool next_combination(RandIt, RandIt, RandIt, Compare) [with RandIt = __gnu_cxx::__normal_iterator > >, Compare = bool]’
equity.cpp:28:   instantiated from here
/usr/include/c++/4.4/tr1_impl/functional:195: error: ‘const volatile bool’ is not a class, struct, or union type
/usr/include/c++/4.4/tr1_impl/functional: In instantiation of ‘std::_Result_of_impl’:
/usr/include/c++/4.4/tr1_impl/functional:149:   instantiated from ‘std::result_of’
/usr/include/c++/4.4/bits/stl_algo.h:2230:   instantiated from ‘_RandomAccessIterator std::__unguarded_partition(_RandomAccessIterator, _RandomAccessIterator, _Tp, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Tp = int, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:2301:   instantiated from ‘void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Size = long int, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:5258:   instantiated from ‘void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’
misc.hpp:13:   instantiated from ‘bool next_combination(RandIt, RandIt, RandIt, Compare) [with RandIt = __gnu_cxx::__normal_iterator > >, Compare = bool]’
equity.cpp:28:   instantiated from here
/usr/include/c++/4.4/tr1_impl/functional:195: error: ‘volatile bool’ is not a class, struct, or union type
/usr/include/c++/4.4/tr1_impl/functional: In instantiation of ‘std::_Result_of_impl’:
/usr/include/c++/4.4/tr1_impl/functional:149:   instantiated from ‘std::result_of’
/usr/include/c++/4.4/bits/stl_algo.h:2230:   instantiated from ‘_RandomAccessIterator std::__unguarded_partition(_RandomAccessIterator, _RandomAccessIterator, _Tp, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Tp = int, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:2301:   instantiated from ‘void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Size = long int, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:5258:   instantiated from ‘void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’
misc.hpp:13:   instantiated from ‘bool next_combination(RandIt, RandIt, RandIt, Compare) [with RandIt = __gnu_cxx::__normal_iterator > >, Compare = bool]’
equity.cpp:28:   instantiated from here
/usr/include/c++/4.4/tr1_impl/functional:195: error: ‘const bool’ is not a class, struct, or union type
/usr/include/c++/4.4/tr1_impl/functional: In instantiation of ‘std::_Result_of_impl’:
/usr/include/c++/4.4/tr1_impl/functional:149:   instantiated from ‘std::result_of’
/usr/include/c++/4.4/bits/stl_algo.h:2230:   instantiated from ‘_RandomAccessIterator std::__unguarded_partition(_RandomAccessIterator, _RandomAccessIterator, _Tp, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Tp = int, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:2301:   instantiated from ‘void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Size = long int, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:5258:   instantiated from ‘void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’
misc.hpp:13:   instantiated from ‘bool next_combination(RandIt, RandIt, RandIt, Compare) [with RandIt = __gnu_cxx::__normal_iterator > >, Compare = bool]’
equity.cpp:28:   instantiated from here
/usr/include/c++/4.4/tr1_impl/functional:195: error: ‘bool’ is not a class, struct, or union type
In file included from /usr/include/c++/4.4/algorithm:62,
                 from misc.hpp:6,
                 from equity.cpp:3:
/usr/include/c++/4.4/bits/stl_algo.h: In function ‘_RandomAccessIterator std::__unguarded_partition(_RandomAccessIterator, _RandomAccessIterator, _Tp, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Tp = int, _Compare = std::_Bind, std::_Placeholder)>]’:
/usr/include/c++/4.4/bits/stl_algo.h:2301:   instantiated from ‘void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Size = long int, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:5258:   instantiated from ‘void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’
misc.hpp:13:   instantiated from ‘bool next_combination(RandIt, RandIt, RandIt, Compare) [with RandIt = __gnu_cxx::__normal_iterator > >, Compare = bool]’
equity.cpp:28:   instantiated from here
/usr/include/c++/4.4/bits/stl_algo.h:2230: error: no match for call to ‘(std::_Bind, std::_Placeholder)>) (int&, int&)’
/usr/include/c++/4.4/bits/stl_algo.h:2233: error: no match for call to ‘(std::_Bind, std::_Placeholder)>) (int&, int&)’
/usr/include/c++/4.4/bits/stl_algo.h: In function ‘void std::__insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’:
/usr/include/c++/4.4/bits/stl_algo.h:2193:   instantiated from ‘void std::__final_insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:5260:   instantiated from ‘void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’
misc.hpp:13:   instantiated from ‘bool next_combination(RandIt, RandIt, RandIt, Compare) [with RandIt = __gnu_cxx::__normal_iterator > >, Compare = bool]’
equity.cpp:28:   instantiated from here
/usr/include/c++/4.4/bits/stl_algo.h:2128: error: no match for call to ‘(std::_Bind, std::_Placeholder)>) (int&, int&)’
/usr/include/c++/4.4/bits/stl_algo.h: In function ‘void std::__heap_select(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’:
/usr/include/c++/4.4/bits/stl_algo.h:5108:   instantiated from ‘void std::partial_sort(_RAIter, _RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:2288:   instantiated from ‘void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Size = long int, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:5258:   instantiated from ‘void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’
misc.hpp:13:   instantiated from ‘bool next_combination(RandIt, RandIt, RandIt, Compare) [with RandIt = __gnu_cxx::__normal_iterator > >, Compare = bool]’
equity.cpp:28:   instantiated from here
/usr/include/c++/4.4/bits/stl_algo.h:1919: error: no match for call to ‘(std::_Bind, std::_Placeholder)>) (int&, int&)’
/usr/include/c++/4.4/bits/stl_algo.h: In function ‘void std::__unguarded_linear_insert(_RandomAccessIterator, _Tp, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Tp = int, _Compare = std::_Bind, std::_Placeholder)>]’:
/usr/include/c++/4.4/bits/stl_algo.h:2134:   instantiated from ‘void std::__insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:2193:   instantiated from ‘void std::__final_insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:5260:   instantiated from ‘void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’
misc.hpp:13:   instantiated from ‘bool next_combination(RandIt, RandIt, RandIt, Compare) [with RandIt = __gnu_cxx::__normal_iterator > >, Compare = bool]’
equity.cpp:28:   instantiated from here
/usr/include/c++/4.4/bits/stl_algo.h:2084: error: no match for call to ‘(std::_Bind, std::_Placeholder)>) (int&, int&)’
In file included from /usr/include/c++/4.4/bits/stl_algo.h:62,
                 from /usr/include/c++/4.4/algorithm:62,
                 from misc.hpp:6,
                 from equity.cpp:3:
/usr/include/c++/4.4/bits/stl_heap.h: In function ‘void std::__adjust_heap(_RandomAccessIterator, _Distance, _Distance, _Tp, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Distance = long int, _Tp = int, _Compare = std::_Bind, std::_Placeholder)>]’:
/usr/include/c++/4.4/bits/stl_heap.h:434:   instantiated from ‘void std::make_heap(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:1917:   instantiated from ‘void std::__heap_select(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:5108:   instantiated from ‘void std::partial_sort(_RAIter, _RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:2288:   instantiated from ‘void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Size = long int, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:5258:   instantiated from ‘void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’
misc.hpp:13:   instantiated from ‘bool next_combination(RandIt, RandIt, RandIt, Compare) [with RandIt = __gnu_cxx::__normal_iterator > >, Compare = bool]’
equity.cpp:28:   instantiated from here
/usr/include/c++/4.4/bits/stl_heap.h:303: error: no match for call to ‘(std::_Bind, std::_Placeholder)>) (int&, int&)’
/usr/include/c++/4.4/bits/stl_heap.h: In function ‘void std::__push_heap(_RandomAccessIterator, _Distance, _Distance, _Tp, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Distance = long int, _Tp = int, _Compare = std::_Bind, std::_Placeholder)>]’:
/usr/include/c++/4.4/bits/stl_heap.h:316:   instantiated from ‘void std::__adjust_heap(_RandomAccessIterator, _Distance, _Distance, _Tp, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Distance = long int, _Tp = int, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_heap.h:434:   instantiated from ‘void std::make_heap(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:1917:   instantiated from ‘void std::__heap_select(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:5108:   instantiated from ‘void std::partial_sort(_RAIter, _RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:2288:   instantiated from ‘void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Size = long int, _Compare = std::_Bind, std::_Placeholder)>]’
/usr/include/c++/4.4/bits/stl_algo.h:5258:   instantiated from ‘void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator > >, _Compare = std::_Bind, std::_Placeholder)>]’
misc.hpp:13:   instantiated from ‘bool next_combination(RandIt, RandIt, RandIt, Compare) [with RandIt = __gnu_cxx::__normal_iterator > >, Compare = bool]’
equity.cpp:28:   instantiated from here
/usr/include/c++/4.4/bits/stl_heap.h:180: error: no match for call to ‘(std::_Bind, std::_Placeholder)>) (int&, int&)’
make: *** [equity.o] Error 1


推荐答案

第二个模板参数不应为 bool 。你可以允许compiller处理类型,只需写:

The second template argument shouldn't be bool. You can allow compiller to handle types and simply write:

while(next_combination(combo.begin(), combo.begin() + to_generate, combo.end(), std::less<int>()))
    for(std::vector<int>::iterator iter = combo.begin(); iter != combo.end() ; ++iter)
        std::cout << *iter << " ";

并使用空格 - 使代码看起来更好。

And use spaces - it makes code look better.

这篇关于此next_combination代码的用法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆