简体   繁体   中英

boost::algorithm::contains std::vector<long> & long value

I am using boost::algorithm::contains(std::vector<long>, long value) and receiving a host of errors.

std::vector<long> instance;
long byteIndex;
// (Perhaps more code?...)
boost::algorithm::contains(instances, byteIndex);

I don't understand this compiler error C2039: 'type' : is not a member of 'boost::range_const_iterator<C>' .

I read the template class and saw a demonstration using std::string

std::string s = "Boris Schäling"; 
boost::algorithm::contains(s, "is");

I do not consider my use of boost's contains any different except I am using a different type. Any idea why boost::algorithm::contains(std::vector<long>, long) won't compile?

boost::algorithm::contains expects two ranges, the input range and the range to search for. You're getting an error because you're providing the first range ( std::vector<long> ) but not the second (you only give a single long value).

You'd be better off using std::find :

std::find(vector.begin(), vector.end(), value) != vector.end()

boost::algorithm::contains takes two ranges. You are searching for a value in your vector.

In your string example, you are searching for the sequence "is" . If you were to search for 'i' (not a sequence, a value), you would get the same error as you are describing with your vector<long> .

The code:

std::vector<long> v { 1,2,3,4,5 };
std::vector<long> v1 { 3, 4 };
boost::algorithm::contains(v, v1);

compiles just fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM