mirror of
https://github.com/boostorg/compute.git
synced 2026-02-19 14:22:12 +00:00
Merge pull request #312 from Mageswaran1989/string_find_string
oveloaded find() for string and char pointer
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
|
||||
#include <boost/compute/cl.hpp>
|
||||
#include <boost/compute/algorithm/find.hpp>
|
||||
#include <boost/compute/algorithm/search.hpp>
|
||||
#include <boost/compute/container/vector.hpp>
|
||||
#include <boost/compute/system.hpp>
|
||||
#include <boost/compute/command_queue.hpp>
|
||||
@@ -247,6 +248,7 @@ public:
|
||||
return basic_string<CharT, Traits>(*this, pos, count);
|
||||
}
|
||||
|
||||
/// Finds the first character \p ch
|
||||
size_type find(CharT ch, size_type pos = 0) const
|
||||
{
|
||||
const_iterator iter = ::boost::compute::find(begin() + pos, end(), ch);
|
||||
@@ -258,6 +260,40 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
/// Finds the first substring equal to \p str
|
||||
size_type find(basic_string& str, size_type pos = 0) const
|
||||
{
|
||||
const_iterator iter = ::boost::compute::search(begin() + pos, end(),
|
||||
str.begin(), str.end());
|
||||
if(iter == end()){
|
||||
return npos;
|
||||
}
|
||||
else {
|
||||
return static_cast<size_type>(std::distance(begin(), iter));
|
||||
}
|
||||
}
|
||||
|
||||
/// Finds the first substring equal to the character string
|
||||
/// pointed to by \p s.
|
||||
/// The length of the string is determined by the first null character.
|
||||
///
|
||||
/// For example, the following code
|
||||
/// \snippet test/test_string.cpp string_find
|
||||
///
|
||||
/// will return 5 as position.
|
||||
size_type find(const char* s, size_type pos = 0) const
|
||||
{
|
||||
basic_string str(s);
|
||||
const_iterator iter = ::boost::compute::search(begin() + pos, end(),
|
||||
str.begin(), str.end());
|
||||
if(iter == end()){
|
||||
return npos;
|
||||
}
|
||||
else {
|
||||
return static_cast<size_type>(std::distance(begin(), iter));
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
::boost::compute::vector<CharT> m_data;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user