指定使用std :: rotate而不是来自boost

时间:2018-02-20 02:55:27

标签: c++ c++11 boost stl

我有一个问题要指定使用来自stl的rotate,而不是来自boost。我该怎么办?

我的整个来源可以在下面看到,这是一个简单的插入排序方法代码

#include <algorithm>    // std::rotate
#include <vector>

// Function to sort the array
struct _ItemCompare {...} ItemCompare;

template<class T>
class Sorters {
public:
    void insertionSort(std::vector<T> &vec, unsigned int size) {
        for (auto it = vec.begin(); it != vec.begin() + size; it++) {
            auto const insertion_point = std::upper_bound(vec.begin(), it, *it, ItemCompare);
            std::rotate(insertion_point, it, it + 1);
        }
    }

};

可以看到错误跟踪跟踪的代码如下:

In file included from src/balanced_intercalation_multipath.cpp:10:0,
                 from src/balanced_intercalation_multipath.h:29,
                 from main.cpp:7:
src/sorters.h: In member function ‘void Sorters<T>::insertionSort(std::vector<T>&, unsigned int)’:
src/sorters.h:29:19: error: ‘it’ does not name a type
         for (auto it = vec.begin(); it != vec.begin() + size; it++) {
                   ^
src/sorters.h:29:37: error: expected ‘;’ before ‘it’
         for (auto it = vec.begin(); it != vec.begin() + size; it++) {
                                     ^
src/sorters.h:29:37: error: ‘it’ was not declared in this scope
In file included from src/balanced_intercalation_multipath.h:29:0,
                 from main.cpp:7:

In file included from /usr/include/c++/4.8/bits/char_traits.h:39:0,
                 from /usr/include/c++/4.8/ios:40,
                 from /usr/include/c++/4.8/ostream:38,
                 from /usr/include/c++/4.8/iostream:39,
                 from main.cpp:1:
/usr/include/c++/4.8/bits/stl_algobase.h:335:18: note: synthesized method ‘Item& Item::operator=(const Item&)’ first required here 
        *__result = *__first;
                  ^
src/sorters.h: In member function ‘void Sorters<T>::insertionSort(std::vector<T>&, unsigned int)’:
src/sorters.h:29:19: error: ‘it’ does not name a type
         for (auto it = vec.begin(); it != vec.begin() + size; it++) {
                   ^
src/sorters.h:29:37: error: expected ‘;’ before ‘it’
         for (auto it = vec.begin(); it != vec.begin() + size; it++) {
                                     ^
src/sorters.h:29:37: error: ‘it’ was not declared in this scope

EDIT1:输入我的整个代码以及错误 我用

编译
  

-lboost_serialization -std = c ++ 11

1 个答案:

答案 0 :(得分:3)

您收到std::rotate,但忘了#include <algorithm>。但是,您正在使用的Boost标头包含了它。

但是,您收到的错误消息与Boost无关。