Pedro
Pedro

Reputation: 15

Specify to use std::rotate not from boost

I'm having a problem to specify to use the rotate from stl, not from boost. How can I do it?

My entire source can be seen below, which is a simple code of insertion sort method

#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);
        }
    }

};

the error track trace can be seen is the code below:

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: Put my entire code and also the error I compile with

-lboost_serialization -std=c++11

Upvotes: 0

Views: 511

Answers (1)

Ben Voigt
Ben Voigt

Reputation: 283634

You are getting std::rotate, but you forgot to #include <algorithm>. However, the Boost headers you are using have included it for you.

The error message you are getting is unrelated to Boost, however.

Upvotes: 3

Related Questions