forked from boostorg/static_string
More constexpr for find_meow, more constexpr tests
This commit is contained in:
@ -507,10 +507,10 @@ BOOST_STATIC_STRING_CPP14_CONSTEXPR
|
|||||||
inline
|
inline
|
||||||
ForwardIterator
|
ForwardIterator
|
||||||
find_not_of(
|
find_not_of(
|
||||||
ForwardIterator first,
|
ForwardIterator first,
|
||||||
ForwardIterator last,
|
ForwardIterator last,
|
||||||
const CharT* str,
|
const CharT* str,
|
||||||
std::size_t n) noexcept
|
std::size_t n) noexcept
|
||||||
{
|
{
|
||||||
for (; first != last; ++first)
|
for (; first != last; ++first)
|
||||||
if (!Traits::find(str, n, *first))
|
if (!Traits::find(str, n, *first))
|
||||||
@ -518,6 +518,57 @@ find_not_of(
|
|||||||
return last;
|
return last;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// constexpr search for C++14
|
||||||
|
template<
|
||||||
|
typename ForwardIt1,
|
||||||
|
typename ForwardIt2,
|
||||||
|
typename BinaryPredicate>
|
||||||
|
BOOST_STATIC_STRING_CPP14_CONSTEXPR
|
||||||
|
inline
|
||||||
|
ForwardIt1
|
||||||
|
search(
|
||||||
|
ForwardIt1 first,
|
||||||
|
ForwardIt1 last,
|
||||||
|
ForwardIt2 s_first,
|
||||||
|
ForwardIt2 s_last,
|
||||||
|
BinaryPredicate p)
|
||||||
|
{
|
||||||
|
for (; ; ++first)
|
||||||
|
{
|
||||||
|
ForwardIt1 it = first;
|
||||||
|
for (ForwardIt2 s_it = s_first; ; ++it, ++s_it)
|
||||||
|
{
|
||||||
|
if (s_it == s_last)
|
||||||
|
return first;
|
||||||
|
if (it == last)
|
||||||
|
return last;
|
||||||
|
if (!p(*it, *s_it))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template<
|
||||||
|
typename InputIt,
|
||||||
|
typename ForwardIt,
|
||||||
|
typename BinaryPredicate>
|
||||||
|
BOOST_STATIC_STRING_CPP14_CONSTEXPR
|
||||||
|
inline
|
||||||
|
InputIt
|
||||||
|
find_first_of(
|
||||||
|
InputIt first,
|
||||||
|
InputIt last,
|
||||||
|
ForwardIt s_first,
|
||||||
|
ForwardIt s_last,
|
||||||
|
BinaryPredicate p)
|
||||||
|
{
|
||||||
|
for (; first != last; ++first)
|
||||||
|
for (ForwardIt it = s_first; it != s_last; ++it)
|
||||||
|
if (p(*first, *it))
|
||||||
|
return first;
|
||||||
|
return last;
|
||||||
|
}
|
||||||
|
|
||||||
} // detail
|
} // detail
|
||||||
} // static_string
|
} // static_string
|
||||||
} // boost
|
} // boost
|
||||||
|
@ -776,7 +776,7 @@ find(
|
|||||||
return npos;
|
return npos;
|
||||||
if (!n)
|
if (!n)
|
||||||
return pos;
|
return pos;
|
||||||
const auto res = std::search(&data()[pos], &data()[curr_size], s, &s[n], Traits::eq);
|
const auto res = detail::search(&data()[pos], &data()[curr_size], s, &s[n], Traits::eq);
|
||||||
return res == end() ? npos : detail::distance(data(), res);
|
return res == end() ? npos : detail::distance(data(), res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -817,7 +817,7 @@ find_first_of(
|
|||||||
const auto curr_data = data();
|
const auto curr_data = data();
|
||||||
if (pos >= size() || !n)
|
if (pos >= size() || !n)
|
||||||
return npos;
|
return npos;
|
||||||
const auto res = std::find_first_of(&curr_data[pos], &curr_data[size()], s, &s[n], Traits::eq);
|
const auto res = detail::find_first_of(&curr_data[pos], &curr_data[size()], s, &s[n], Traits::eq);
|
||||||
return res == end() ? npos : detail::distance(curr_data, res);
|
return res == end() ? npos : detail::distance(curr_data, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -838,7 +838,7 @@ find_last_of(
|
|||||||
pos = 0;
|
pos = 0;
|
||||||
else
|
else
|
||||||
pos = curr_size - (pos + 1);
|
pos = curr_size - (pos + 1);
|
||||||
const auto res = std::find_first_of(rbegin() + pos, rend(), s, &s[n], Traits::eq);
|
const auto res = detail::find_first_of(rbegin() + pos, rend(), s, &s[n], Traits::eq);
|
||||||
return res == rend() ? npos : curr_size - 1 - detail::distance(rbegin(), res);
|
return res == rend() ? npos : curr_size - 1 - detail::distance(rbegin(), res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1996,7 +1996,7 @@ public:
|
|||||||
template<std::size_t M>
|
template<std::size_t M>
|
||||||
BOOST_STATIC_STRING_CPP14_CONSTEXPR
|
BOOST_STATIC_STRING_CPP14_CONSTEXPR
|
||||||
size_type
|
size_type
|
||||||
find(
|
find(
|
||||||
const basic_static_string<M, CharT, Traits>& str,
|
const basic_static_string<M, CharT, Traits>& str,
|
||||||
size_type pos = 0) const noexcept
|
size_type pos = 0) const noexcept
|
||||||
{
|
{
|
||||||
|
@ -39,6 +39,20 @@ testConstantEvaluation()
|
|||||||
return true;
|
return true;
|
||||||
#elif defined(BOOST_STATIC_STRING_CPP17_CONSTEXPR_USED)
|
#elif defined(BOOST_STATIC_STRING_CPP17_CONSTEXPR_USED)
|
||||||
// c++17 constexpr tests
|
// c++17 constexpr tests
|
||||||
|
|
||||||
|
/*
|
||||||
|
{
|
||||||
|
auto j = a.rbegin();
|
||||||
|
}
|
||||||
|
{
|
||||||
|
auto j = a.crbegin();
|
||||||
|
}
|
||||||
|
{
|
||||||
|
auto j = a.rend();
|
||||||
|
}
|
||||||
|
{
|
||||||
|
auto j = a.crend();
|
||||||
|
}*/
|
||||||
return true;
|
return true;
|
||||||
#elif defined(BOOST_STATIC_STRING_CPP14_CONSTEXPR_USED)
|
#elif defined(BOOST_STATIC_STRING_CPP14_CONSTEXPR_USED)
|
||||||
// c++14 constexpr tests
|
// c++14 constexpr tests
|
||||||
@ -100,19 +114,6 @@ testConstantEvaluation()
|
|||||||
{
|
{
|
||||||
auto j = a.cend();
|
auto j = a.cend();
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
{
|
|
||||||
auto j = a.rbegin();
|
|
||||||
}
|
|
||||||
{
|
|
||||||
auto j = a.crbegin();
|
|
||||||
}
|
|
||||||
{
|
|
||||||
auto j = a.rend();
|
|
||||||
}
|
|
||||||
{
|
|
||||||
auto j = a.crend();
|
|
||||||
}*/
|
|
||||||
|
|
||||||
// capacity and size
|
// capacity and size
|
||||||
auto j = cstatic_string().size() +
|
auto j = cstatic_string().size() +
|
||||||
@ -126,7 +127,6 @@ testConstantEvaluation()
|
|||||||
|
|
||||||
// insert
|
// insert
|
||||||
a.insert(a.begin(), 1, 'a');
|
a.insert(a.begin(), 1, 'a');
|
||||||
// cannot have a pointer outside the same array due to UB
|
|
||||||
a.insert(0, a.begin());
|
a.insert(0, a.begin());
|
||||||
a.insert(0, a.begin(), 1);
|
a.insert(0, a.begin(), 1);
|
||||||
a.insert(a.begin(), 'a');
|
a.insert(a.begin(), 'a');
|
||||||
@ -141,6 +141,87 @@ testConstantEvaluation()
|
|||||||
a.push_back('a');
|
a.push_back('a');
|
||||||
a.pop_back();
|
a.pop_back();
|
||||||
|
|
||||||
|
// append
|
||||||
|
a.append(1, 'a');
|
||||||
|
a.append("a", 1);
|
||||||
|
a.append("a");
|
||||||
|
a.append(a.begin(), a.end());
|
||||||
|
a.append({'a'});
|
||||||
|
|
||||||
|
// append operator
|
||||||
|
a += 'a';
|
||||||
|
a += "a";
|
||||||
|
a += {'a'};
|
||||||
|
|
||||||
|
// compare
|
||||||
|
a.compare(b);
|
||||||
|
a.compare(0, 1, b);
|
||||||
|
a.compare(0, 1, b, 0, 1);
|
||||||
|
a.compare("a");
|
||||||
|
a.compare(0, 1, "a");
|
||||||
|
a.compare(0, 1, "a", 1);
|
||||||
|
|
||||||
|
// substr
|
||||||
|
a.substr(0);
|
||||||
|
|
||||||
|
// subview
|
||||||
|
a.subview(0);
|
||||||
|
|
||||||
|
// copy
|
||||||
|
char k[20]{};
|
||||||
|
a.copy(k, 1, 0);
|
||||||
|
|
||||||
|
// resize
|
||||||
|
a.resize(1);
|
||||||
|
a.resize(1, 'a');
|
||||||
|
|
||||||
|
// swap
|
||||||
|
a.swap(b);
|
||||||
|
|
||||||
|
// replace
|
||||||
|
a.replace(0, 1, a);
|
||||||
|
a.replace(0, 1, a, 0, 1);
|
||||||
|
a.replace(0, 1, a.data(), 1);
|
||||||
|
a.replace(0, 1, a.data());
|
||||||
|
a.replace(0, 1, 1, 'a');
|
||||||
|
a.replace(a.begin(), a.end(), a);
|
||||||
|
a.replace(a.begin(), a.end(), a.data(), 1);
|
||||||
|
a.replace(a.begin(), a.end(), a.data());
|
||||||
|
a.replace(a.begin(), a.end(), 1, 'a');
|
||||||
|
a.replace(a.begin(), a.end(), a.begin(), a.end());
|
||||||
|
a.replace(a.begin(), a.end(), {'a'});
|
||||||
|
|
||||||
|
// find
|
||||||
|
a.find(a);
|
||||||
|
a.find("a", 0, 1);
|
||||||
|
a.find("a", 0);
|
||||||
|
a.find('a', 0);
|
||||||
|
|
||||||
|
// rfind
|
||||||
|
a.rfind(a);
|
||||||
|
a.rfind("a", 0, 1);
|
||||||
|
a.rfind("a", 0);
|
||||||
|
a.rfind('a', 0);
|
||||||
|
|
||||||
|
// find_first_of
|
||||||
|
a.find_first_of(a);
|
||||||
|
a.find_first_of("a", 0, 1);
|
||||||
|
a.find_first_of("a", 0);
|
||||||
|
a.find_first_of('a', 0);
|
||||||
|
|
||||||
|
// find_first_not_of
|
||||||
|
a.find_first_not_of(a);
|
||||||
|
a.find_first_not_of("a", 0, 1);
|
||||||
|
a.find_first_not_of("a", 0);
|
||||||
|
a.find_first_not_of('a', 0);
|
||||||
|
|
||||||
|
// starts_with
|
||||||
|
a.starts_with('a');
|
||||||
|
a.starts_with("a");
|
||||||
|
|
||||||
|
// ends_with
|
||||||
|
a.ends_with('a');
|
||||||
|
a.ends_with("a");
|
||||||
return true;
|
return true;
|
||||||
#elif defined(BOOST_STATIC_STRING_CPP11_CONSTEXPR_USED)
|
#elif defined(BOOST_STATIC_STRING_CPP11_CONSTEXPR_USED)
|
||||||
// c++11 constexpr tests
|
// c++11 constexpr tests
|
||||||
|
Reference in New Issue
Block a user