本文整理汇总了C++中SV类的典型用法代码示例。如果您正苦于以下问题:C++ SV类的具体用法?C++ SV怎么用?C++ SV使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SV类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int, char**)
{
{
typedef std::string_view S;
test0<S>();
test1<S>();
test2<S>();
test3<S>();
}
#if TEST_STD_VER > 11
{
typedef std::basic_string_view<char, constexpr_char_traits<char>> SV;
constexpr SV sv1;
constexpr SV sv2 { "abcde", 5 };
static_assert (sv1.find_last_of( "", 0, 0) == SV::npos, "" );
static_assert (sv1.find_last_of( "irkhs", 0, 5) == SV::npos, "" );
static_assert (sv2.find_last_of( "", 0, 0) == SV::npos, "" );
static_assert (sv2.find_last_of( "gfsrt", 5, 5) == SV::npos, "" );
static_assert (sv2.find_last_of( "lecar", 5, 5) == 4, "" );
}
#endif
return 0;
}
示例2: main
int main(int, char**)
{
{
typedef std::string_view SV;
SV sv1 {};
SV sv2 { "abcde", 5 };
ASSERT_NOEXCEPT(sv1.starts_with('e'));
assert (!sv1.starts_with('a'));
assert (!sv1.starts_with('x'));
assert ( sv2.starts_with('a'));
assert (!sv2.starts_with('x'));
}
#if TEST_STD_VER > 11
{
typedef std::basic_string_view<char, constexpr_char_traits<char>> SV;
constexpr SV sv1 {};
constexpr SV sv2 { "abcde", 5 };
static_assert (!sv1.starts_with('a'), "" );
static_assert (!sv1.starts_with('x'), "" );
static_assert ( sv2.starts_with('a'), "" );
static_assert (!sv2.starts_with('x'), "" );
}
#endif
return 0;
}
示例3: test
void test ( const CharT *s, size_t len ) {
typedef std::basic_string_view<CharT> SV;
SV sv ( s, len );
ASSERT_SAME_TYPE(decltype(sv[0]), typename SV::const_reference);
LIBCPP_ASSERT_NOEXCEPT( sv[0]);
assert ( sv.length() == len );
for ( size_t i = 0; i < len; ++i ) {
assert ( sv[i] == s[i] );
assert ( &sv[i] == s + i );
}
}
示例4: split
SV split(string s1){
SV v;
string s="/";
for(int i=1;s1[i];++i){
if(s1[i]=='/'){
v.pb(s);
}
s+=s1[i];
}
v.pb(s);
return v;
}
示例5: test_npos
void
test_npos(S s, SV sv, typename S::size_type pos, S expected)
{
try
{
s.append(sv, pos);
LIBCPP_ASSERT(s.__invariants());
assert(pos <= sv.size());
assert(s == expected);
}
catch (std::out_of_range&)
{
assert(pos > sv.size());
}
}
示例6: test
void
test(const S& s, SV sv, typename S::size_type x)
{
assert(s.rfind(sv) == x);
if (x != S::npos)
assert(0 <= x && x + sv.size() <= s.size());
}
示例7: main
int main()
{
{
typedef std::string_view S;
test(S(""), 'q', 0, S::npos);
test(S(""), 'q', 1, S::npos);
test(S("kitcj"), 'q', 0, 0);
test(S("qkamf"), 'q', 1, 1);
test(S("nhmko"), 'q', 2, 2);
test(S("tpsaf"), 'q', 4, 4);
test(S("lahfb"), 'q', 5, S::npos);
test(S("irkhs"), 'q', 6, S::npos);
test(S("gmfhdaipsr"), 'q', 0, 0);
test(S("kantesmpgj"), 'q', 1, 1);
test(S("odaftiegpm"), 'q', 5, 5);
test(S("oknlrstdpi"), 'q', 9, 9);
test(S("eolhfgpjqk"), 'q', 10, S::npos);
test(S("pcdrofikas"), 'q', 11, S::npos);
test(S("nbatdlmekrgcfqsophij"), 'q', 0, 0);
test(S("bnrpehidofmqtcksjgla"), 'q', 1, 1);
test(S("jdmciepkaqgotsrfnhlb"), 'q', 10, 10);
test(S("jtdaefblsokrmhpgcnqi"), 'q', 19, 19);
test(S("hkbgspofltajcnedqmri"), 'q', 20, S::npos);
test(S("oselktgbcapndfjihrmq"), 'q', 21, S::npos);
test(S(""), 'q', S::npos);
test(S("q"), 'q', S::npos);
test(S("qqq"), 'q', S::npos);
test(S("csope"), 'q', 0);
test(S("gfsmthlkon"), 'q', 0);
test(S("laenfsbridchgotmkqpj"), 'q', 0);
}
#if _LIBCPP_STD_VER > 11
{
typedef std::basic_string_view<char, constexpr_char_traits<char>> SV;
constexpr SV sv1;
constexpr SV sv2 { "abcde", 5 };
static_assert (sv1.find_first_not_of( 'q', 0 ) == SV::npos, "" );
static_assert (sv1.find_first_not_of( 'q', 1 ) == SV::npos, "" );
static_assert (sv2.find_first_not_of( 'q', 0 ) == 0, "" );
static_assert (sv2.find_first_not_of( 'q', 1 ) == 1, "" );
static_assert (sv2.find_first_not_of( 'q', 5 ) == SV::npos, "" );
}
#endif
}
示例8: test
void test()
{
typedef ox::fit::static_vector<int[4]> SV;
SV sv;
sv.push_back(1);
//sv.push_back(2);
//sv.push_back(3);
//sv.push_back(4);
//sv.push_back(5);
//typedef ox::fit::static_string<char[4]> SS;
//SS ss;
//ss.push_back('1');
//ss.push_back('2');
//ss.push_back('3');
//ss.push_back('4');
}
示例9: main
int main () {
test0();
test1();
test2();
{
test("abcde", 5, 1, "", 0);
test("abcde", 2, 4, "", 3);
test("abcde", 2, 4, "abcde", 2);
test("ABCde", 2, 4, "abcde", -1);
}
{
test(L"abcde", 5, 1, L"", 0);
test(L"abcde", 2, 4, L"", 3);
test(L"abcde", 2, 4, L"abcde", 2);
test(L"ABCde", 2, 4, L"abcde", -1);
}
#if __cplusplus >= 201103L
{
test(u"abcde", 5, 1, u"", 0);
test(u"abcde", 2, 4, u"", 3);
test(u"abcde", 2, 4, u"abcde", 2);
test(u"ABCde", 2, 4, u"abcde", -1);
}
{
test(U"abcde", 5, 1, U"", 0);
test(U"abcde", 2, 4, U"", 3);
test(U"abcde", 2, 4, U"abcde", 2);
test(U"ABCde", 2, 4, U"abcde", -1);
}
#endif
#if _LIBCPP_STD_VER > 11
{
typedef std::experimental::basic_string_view<char, constexpr_char_traits<char>> SV;
constexpr SV sv1 { "abcde", 5 };
constexpr SV sv2 { "abcde", 0 };
static_assert ( sv1.compare(5, 1, sv2) == 0, "" );
static_assert ( sv1.compare(2, 4, sv2) == 1, "" );
}
#endif
}
示例10: main
int main()
{
{
typedef std::experimental::string_view S;
test0<S>();
test1<S>();
test2<S>();
test3<S>();
}
#if TEST_STD_VER > 11
{
typedef std::experimental::basic_string_view<char, constexpr_char_traits<char>> SV;
constexpr SV sv1;
constexpr SV sv2 { "abcde", 5 };
static_assert (sv1.find( "", 0, 0 ) == 0, "" );
static_assert (sv1.find( "abcde", 0, 0 ) == 0, "" );
static_assert (sv1.find( "abcde", 0, 1 ) == SV::npos, "" );
static_assert (sv2.find( "", 0, 0 ) == 0, "" );
static_assert (sv2.find( "abcde", 0, 0 ) == 0, "" );
static_assert (sv2.find( "abcde", 0, 1 ) == 0, "" );
}
#endif
}
示例11: main
int main()
{
{
typedef std::experimental::string_view S;
test0<S>();
test1<S>();
}
#if TEST_STD_VER > 11
{
typedef std::experimental::basic_string_view<char, constexpr_char_traits<char>> SV;
constexpr SV sv1;
constexpr SV sv2 { "abcde", 5 };
static_assert (sv1.find_last_not_of( "", 0) == SV::npos, "" );
static_assert (sv1.find_last_not_of( "irkhs", 5) == SV::npos, "" );
static_assert (sv2.find_last_not_of( "", 0) == 0, "" );
static_assert (sv2.find_last_not_of( "gfsrt", 5) == 4, "" );
static_assert (sv2.find_last_not_of( "lecar", 5) == 3, "" );
}
#endif
}
示例12: main
int main()
{
{
typedef std::string_view S;
test0<S>();
test1<S>();
}
#if _LIBCPP_STD_VER > 11
{
typedef std::basic_string_view<char, constexpr_char_traits<char>> SV;
constexpr SV sv1;
constexpr SV sv2 { "abcde", 5 };
static_assert (sv1.find(sv1) == 0, "" );
static_assert (sv1.find(sv2) == SV::npos, "" );
static_assert (sv2.find(sv1) == 0, "" );
static_assert (sv2.find(sv2) == 0, "" );
static_assert (sv2.find(sv2, 1 ) == SV::npos, "" );
}
#endif
}
示例13: test1
void test1 () {
#if _LIBCPP_STD_VER > 11
{
constexpr SV sv1;
static_assert ( sv1.size() == 0, "" );
static_assert ( sv1.empty(), "");
static_assert ( sv1.size() == sv1.length(), "" );
static_assert ( sv1.max_size() > sv1.size(), "");
}
#endif
{
SV sv1;
assert ( sv1.size() == 0 );
assert ( sv1.empty());
assert ( sv1.size() == sv1.length());
assert ( sv1.max_size() > sv1.size());
}
}
示例14: main
int main()
{
{
typedef std::string_view S;
test(S(""), 'c', 0, S::npos);
test(S(""), 'c', 1, S::npos);
test(S("abcde"), 'c', 0, 2);
test(S("abcde"), 'c', 1, 2);
test(S("abcde"), 'c', 2, 2);
test(S("abcde"), 'c', 4, S::npos);
test(S("abcde"), 'c', 5, S::npos);
test(S("abcde"), 'c', 6, S::npos);
test(S("abcdeabcde"), 'c', 0, 2);
test(S("abcdeabcde"), 'c', 1, 2);
test(S("abcdeabcde"), 'c', 5, 7);
test(S("abcdeabcde"), 'c', 9, S::npos);
test(S("abcdeabcde"), 'c', 10, S::npos);
test(S("abcdeabcde"), 'c', 11, S::npos);
test(S("abcdeabcdeabcdeabcde"), 'c', 0, 2);
test(S("abcdeabcdeabcdeabcde"), 'c', 1, 2);
test(S("abcdeabcdeabcdeabcde"), 'c', 10, 12);
test(S("abcdeabcdeabcdeabcde"), 'c', 19, S::npos);
test(S("abcdeabcdeabcdeabcde"), 'c', 20, S::npos);
test(S("abcdeabcdeabcdeabcde"), 'c', 21, S::npos);
test(S(""), 'c', S::npos);
test(S("abcde"), 'c', 2);
test(S("abcdeabcde"), 'c', 2);
test(S("abcdeabcdeabcdeabcde"), 'c', 2);
}
#if _LIBCPP_STD_VER > 11
{
typedef std::basic_string_view<char, constexpr_char_traits<char>> SV;
constexpr SV sv1;
constexpr SV sv2 { "abcde", 5 };
static_assert (sv1.find( 'c', 0 ) == SV::npos, "" );
static_assert (sv1.find( 'c', 1 ) == SV::npos, "" );
static_assert (sv2.find( 'c', 0 ) == 2, "" );
static_assert (sv2.find( 'c', 1 ) == 2, "" );
static_assert (sv2.find( 'c', 2 ) == 2, "" );
static_assert (sv2.find( 'c', 3 ) == SV::npos, "" );
static_assert (sv2.find( 'c', 4 ) == SV::npos, "" );
}
#endif
}
示例15: main
int main()
{
{
typedef std::string_view SV;
const char *s = "abcde";
SV sv0 {};
SV sv1 { s + 4, 1 };
SV sv2 { s + 3, 2 };
// SV sv3 { s + 2, 3 };
// SV sv4 { s + 1, 4 };
// SV sv5 { s , 5 };
SV svNot {"def", 3 };
LIBCPP_ASSERT_NOEXCEPT(sv0.ends_with(""));
assert ( sv0.ends_with(""));
assert (!sv0.ends_with("e"));
assert ( sv1.ends_with(""));
assert ( sv1.ends_with("e"));
assert (!sv1.ends_with("de"));
assert (!sv1.ends_with("cde"));
assert (!sv1.ends_with("bcde"));
assert (!sv1.ends_with("abcde"));
assert (!sv1.ends_with("def"));
assert ( sv2.ends_with(""));
assert ( sv2.ends_with("e"));
assert ( sv2.ends_with("de"));
assert (!sv2.ends_with("cde"));
assert (!sv2.ends_with("bcde"));
assert (!sv2.ends_with("abcde"));
assert (!sv2.ends_with("def"));
assert ( svNot.ends_with(""));
assert (!svNot.ends_with("e"));
assert (!svNot.ends_with("de"));
assert (!svNot.ends_with("cde"));
assert (!svNot.ends_with("bcde"));
assert (!svNot.ends_with("abcde"));
assert ( svNot.ends_with("def"));
}
#if TEST_STD_VER > 11
{
typedef std::basic_string_view<char, constexpr_char_traits<char>> SV;
constexpr const char *s = "abcde";
constexpr SV sv0 {};
constexpr SV sv1 { s + 4, 1 };
constexpr SV sv2 { s + 3, 2 };
// constexpr SV sv3 { s + 2, 3 };
// constexpr SV sv4 { s + 1, 4 };
// constexpr SV sv5 { s, 5 };
constexpr SV svNot {"def", 3 };
static_assert ( sv0.ends_with(""), "" );
static_assert (!sv0.ends_with("e"), "" );
static_assert ( sv1.ends_with(""), "" );
static_assert ( sv1.ends_with("e"), "" );
static_assert (!sv1.ends_with("de"), "" );
static_assert (!sv1.ends_with("cde"), "" );
static_assert (!sv1.ends_with("bcde"), "" );
static_assert (!sv1.ends_with("abcde"), "" );
static_assert (!sv1.ends_with("def"), "" );
static_assert ( sv2.ends_with(""), "" );
static_assert ( sv2.ends_with("e"), "" );
static_assert ( sv2.ends_with("de"), "" );
static_assert (!sv2.ends_with("cde"), "" );
static_assert (!sv2.ends_with("bcde"), "" );
static_assert (!sv2.ends_with("abcde"), "" );
static_assert (!sv2.ends_with("def"), "" );
static_assert ( svNot.ends_with(""), "" );
static_assert (!svNot.ends_with("e"), "" );
static_assert (!svNot.ends_with("de"), "" );
static_assert (!svNot.ends_with("cde"), "" );
static_assert (!svNot.ends_with("bcde"), "" );
static_assert (!svNot.ends_with("abcde"), "" );
static_assert ( svNot.ends_with("def"), "" );
}
#endif
}