mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-02-10 19:34:29 +00:00
Implement LWG #2268: Setting a default argument in the declaration of a member function assign of std::basic_string.
llvm-svn: 202876
This commit is contained in:
parent
5aa88fe1e7
commit
53b88dad6f
@ -161,7 +161,7 @@ public:
|
||||
basic_string& operator+=(initializer_list<value_type>);
|
||||
|
||||
basic_string& append(const basic_string& str);
|
||||
basic_string& append(const basic_string& str, size_type pos, size_type n);
|
||||
basic_string& append(const basic_string& str, size_type pos, size_type n=npos); //C++14
|
||||
basic_string& append(const value_type* s, size_type n);
|
||||
basic_string& append(const value_type* s);
|
||||
basic_string& append(size_type n, value_type c);
|
||||
@ -178,7 +178,7 @@ public:
|
||||
|
||||
basic_string& assign(const basic_string& str);
|
||||
basic_string& assign(basic_string&& str);
|
||||
basic_string& assign(const basic_string& str, size_type pos, size_type n);
|
||||
basic_string& assign(const basic_string& str, size_type pos, size_type n=npos); // C++14
|
||||
basic_string& assign(const value_type* s, size_type n);
|
||||
basic_string& assign(const value_type* s);
|
||||
basic_string& assign(size_type n, value_type c);
|
||||
@ -189,7 +189,7 @@ public:
|
||||
basic_string& insert(size_type pos1, const basic_string& str);
|
||||
basic_string& insert(size_type pos1, const basic_string& str,
|
||||
size_type pos2, size_type n);
|
||||
basic_string& insert(size_type pos, const value_type* s, size_type n);
|
||||
basic_string& insert(size_type pos, const value_type* s, size_type n=npos); //C++14
|
||||
basic_string& insert(size_type pos, const value_type* s);
|
||||
basic_string& insert(size_type pos, size_type n, value_type c);
|
||||
iterator insert(const_iterator p, value_type c);
|
||||
@ -204,7 +204,7 @@ public:
|
||||
|
||||
basic_string& replace(size_type pos1, size_type n1, const basic_string& str);
|
||||
basic_string& replace(size_type pos1, size_type n1, const basic_string& str,
|
||||
size_type pos2, size_type n2);
|
||||
size_type pos2, size_type n2=npos); // C++14
|
||||
basic_string& replace(size_type pos, size_type n1, const value_type* s, size_type n2);
|
||||
basic_string& replace(size_type pos, size_type n1, const value_type* s);
|
||||
basic_string& replace(size_type pos, size_type n1, size_type n2, value_type c);
|
||||
@ -261,7 +261,7 @@ public:
|
||||
int compare(const basic_string& str) const noexcept;
|
||||
int compare(size_type pos1, size_type n1, const basic_string& str) const;
|
||||
int compare(size_type pos1, size_type n1, const basic_string& str,
|
||||
size_type pos2, size_type n2) const;
|
||||
size_type pos2, size_type n2=npos) const; // C++14
|
||||
int compare(const value_type* s) const noexcept;
|
||||
int compare(size_type pos1, size_type n1, const value_type* s) const;
|
||||
int compare(size_type pos1, size_type n1, const value_type* s, size_type n2) const;
|
||||
@ -1426,7 +1426,7 @@ public:
|
||||
|
||||
_LIBCPP_INLINE_VISIBILITY
|
||||
basic_string& append(const basic_string& __str);
|
||||
basic_string& append(const basic_string& __str, size_type __pos, size_type __n);
|
||||
basic_string& append(const basic_string& __str, size_type __pos, size_type __n=npos);
|
||||
basic_string& append(const value_type* __s, size_type __n);
|
||||
basic_string& append(const value_type* __s);
|
||||
basic_string& append(size_type __n, value_type __c);
|
||||
@ -1465,7 +1465,7 @@ public:
|
||||
basic_string& assign(basic_string&& str)
|
||||
{*this = _VSTD::move(str); return *this;}
|
||||
#endif
|
||||
basic_string& assign(const basic_string& __str, size_type __pos, size_type __n);
|
||||
basic_string& assign(const basic_string& __str, size_type __pos, size_type __n=npos);
|
||||
basic_string& assign(const value_type* __s, size_type __n);
|
||||
basic_string& assign(const value_type* __s);
|
||||
basic_string& assign(size_type __n, value_type __c);
|
||||
@ -1491,7 +1491,7 @@ public:
|
||||
|
||||
_LIBCPP_INLINE_VISIBILITY
|
||||
basic_string& insert(size_type __pos1, const basic_string& __str);
|
||||
basic_string& insert(size_type __pos1, const basic_string& __str, size_type __pos2, size_type __n);
|
||||
basic_string& insert(size_type __pos1, const basic_string& __str, size_type __pos2, size_type __n=npos);
|
||||
basic_string& insert(size_type __pos, const value_type* __s, size_type __n);
|
||||
basic_string& insert(size_type __pos, const value_type* __s);
|
||||
basic_string& insert(size_type __pos, size_type __n, value_type __c);
|
||||
@ -1527,7 +1527,7 @@ public:
|
||||
|
||||
_LIBCPP_INLINE_VISIBILITY
|
||||
basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str);
|
||||
basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2);
|
||||
basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2=npos);
|
||||
basic_string& replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2);
|
||||
basic_string& replace(size_type __pos, size_type __n1, const value_type* __s);
|
||||
basic_string& replace(size_type __pos, size_type __n1, size_type __n2, value_type __c);
|
||||
@ -1619,7 +1619,7 @@ public:
|
||||
int compare(const basic_string& __str) const _NOEXCEPT;
|
||||
_LIBCPP_INLINE_VISIBILITY
|
||||
int compare(size_type __pos1, size_type __n1, const basic_string& __str) const;
|
||||
int compare(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2) const;
|
||||
int compare(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2=npos) const;
|
||||
int compare(const value_type* __s) const _NOEXCEPT;
|
||||
int compare(size_type __pos1, size_type __n1, const value_type* __s) const;
|
||||
int compare(size_type __pos1, size_type __n1, const value_type* __s, size_type __n2) const;
|
||||
|
@ -10,7 +10,8 @@
|
||||
// <string>
|
||||
|
||||
// basic_string<charT,traits,Allocator>&
|
||||
// append(const basic_string<charT,traits>& str, size_type pos, size_type n);
|
||||
// append(const basic_string<charT,traits>& str, size_type pos, size_type n = npos);
|
||||
// the "= npos" was added for C++14
|
||||
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
@ -35,6 +36,23 @@ test(S s, S str, typename S::size_type pos, typename S::size_type n, S expected)
|
||||
}
|
||||
}
|
||||
|
||||
template <class S>
|
||||
void
|
||||
test_npos(S s, S str, typename S::size_type pos, S expected)
|
||||
{
|
||||
try
|
||||
{
|
||||
s.append(str, pos);
|
||||
assert(s.__invariants());
|
||||
assert(pos <= str.size());
|
||||
assert(s == expected);
|
||||
}
|
||||
catch (std::out_of_range&)
|
||||
{
|
||||
assert(pos > str.size());
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
@ -87,4 +105,14 @@ int main()
|
||||
S("123456789012345678906789012345"));
|
||||
}
|
||||
#endif
|
||||
{
|
||||
typedef std::string S;
|
||||
test_npos(S(), S(), 0, S());
|
||||
test_npos(S(), S(), 1, S());
|
||||
test_npos(S(), S("12345"), 0, S("12345"));
|
||||
test_npos(S(), S("12345"), 1, S("2345"));
|
||||
test_npos(S(), S("12345"), 3, S("45"));
|
||||
test_npos(S(), S("12345"), 5, S(""));
|
||||
test_npos(S(), S("12345"), 6, S("not happening"));
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,8 @@
|
||||
// <string>
|
||||
|
||||
// basic_string<charT,traits,Allocator>&
|
||||
// assign(const basic_string<charT,traits>& str, size_type pos, size_type n);
|
||||
// assign(const basic_string<charT,traits>& str, size_type pos, size_type n=npos);
|
||||
// the =npos was added for C++14
|
||||
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
@ -35,6 +36,23 @@ test(S s, S str, typename S::size_type pos, typename S::size_type n, S expected)
|
||||
}
|
||||
}
|
||||
|
||||
template <class S>
|
||||
void
|
||||
test_npos(S s, S str, typename S::size_type pos, S expected)
|
||||
{
|
||||
try
|
||||
{
|
||||
s.assign(str, pos);
|
||||
assert(s.__invariants());
|
||||
assert(pos <= str.size());
|
||||
assert(s == expected);
|
||||
}
|
||||
catch (std::out_of_range&)
|
||||
{
|
||||
assert(pos > str.size());
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
@ -87,4 +105,14 @@ int main()
|
||||
S("6789012345"));
|
||||
}
|
||||
#endif
|
||||
{
|
||||
typedef std::string S;
|
||||
test_npos(S(), S(), 0, S());
|
||||
test_npos(S(), S(), 1, S());
|
||||
test_npos(S(), S("12345"), 0, S("12345"));
|
||||
test_npos(S(), S("12345"), 1, S("2345"));
|
||||
test_npos(S(), S("12345"), 3, S("45"));
|
||||
test_npos(S(), S("12345"), 5, S(""));
|
||||
test_npos(S(), S("12345"), 6, S("not happening"));
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,8 @@
|
||||
|
||||
// basic_string<charT,traits,Allocator>&
|
||||
// insert(size_type pos1, const basic_string<charT,traits,Allocator>& str,
|
||||
// size_type pos2, size_type n);
|
||||
// size_type pos2, size_type n=npos);
|
||||
// the "=npos" was added in C++14
|
||||
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
@ -40,6 +41,27 @@ test(S s, typename S::size_type pos1, S str, typename S::size_type pos2,
|
||||
}
|
||||
}
|
||||
|
||||
template <class S>
|
||||
void
|
||||
test_npos(S s, typename S::size_type pos1, S str, typename S::size_type pos2, S expected)
|
||||
{
|
||||
typename S::size_type old_size = s.size();
|
||||
S s0 = s;
|
||||
try
|
||||
{
|
||||
s.insert(pos1, str, pos2);
|
||||
assert(s.__invariants());
|
||||
assert(pos1 <= old_size && pos2 <= str.size());
|
||||
assert(s == expected);
|
||||
}
|
||||
catch (std::out_of_range&)
|
||||
{
|
||||
assert(pos1 > old_size || pos2 > str.size());
|
||||
assert(s == s0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template <class S>
|
||||
void test0()
|
||||
{
|
||||
@ -1670,6 +1692,23 @@ void test29()
|
||||
test(S("abcdefghijklmnopqrst"), 21, S("12345678901234567890"), 21, 0, S("can't happen"));
|
||||
}
|
||||
|
||||
template <class S>
|
||||
void test30()
|
||||
{
|
||||
test_npos(S(""), 0, S("12345678901234567890"), 0, S("12345678901234567890"));
|
||||
test_npos(S(""), 0, S("12345678901234567890"), 1, S( "2345678901234567890"));
|
||||
test_npos(S(""), 0, S("12345678901234567890"), 2, S( "345678901234567890"));
|
||||
test_npos(S(""), 0, S("12345678901234567890"), 3, S( "45678901234567890"));
|
||||
test_npos(S(""), 0, S("12345678901234567890"), 5, S( "678901234567890"));
|
||||
test_npos(S(""), 0, S("12345678901234567890"), 10, S( "1234567890"));
|
||||
test_npos(S(""), 0, S("12345678901234567890"), 21, S("can't happen"));
|
||||
test_npos(S("abcdefghijklmnopqrst"), 10, S("12345"), 0, S("abcdefghij12345klmnopqrst"));
|
||||
test_npos(S("abcdefghijklmnopqrst"), 10, S("12345"), 1, S("abcdefghij2345klmnopqrst"));
|
||||
test_npos(S("abcdefghijklmnopqrst"), 10, S("12345"), 3, S("abcdefghij45klmnopqrst"));
|
||||
test_npos(S("abcdefghijklmnopqrst"), 10, S("12345"), 5, S("abcdefghijklmnopqrst"));
|
||||
test_npos(S("abcdefghijklmnopqrst"), 10, S("12345"), 6, S("can't happen"));
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
@ -1704,6 +1743,7 @@ int main()
|
||||
test27<S>();
|
||||
test28<S>();
|
||||
test29<S>();
|
||||
test30<S>();
|
||||
}
|
||||
#if __cplusplus >= 201103L
|
||||
{
|
||||
@ -1738,6 +1778,7 @@ int main()
|
||||
test27<S>();
|
||||
test28<S>();
|
||||
test29<S>();
|
||||
test30<S>();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@ -11,7 +11,8 @@
|
||||
|
||||
// basic_string<charT,traits,Allocator>&
|
||||
// replace(size_type pos1, size_type n1, const basic_string<charT,traits,Allocator>& str,
|
||||
// size_type pos2, size_type n2);
|
||||
// size_type pos2, size_type n2=npos);
|
||||
// the "=npos" was added in C++14
|
||||
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
@ -45,6 +46,32 @@ test(S s, typename S::size_type pos1, typename S::size_type n1,
|
||||
}
|
||||
}
|
||||
|
||||
template <class S>
|
||||
void
|
||||
test_npos(S s, typename S::size_type pos1, typename S::size_type n1,
|
||||
S str, typename S::size_type pos2,
|
||||
S expected)
|
||||
{
|
||||
typename S::size_type old_size = s.size();
|
||||
S s0 = s;
|
||||
try
|
||||
{
|
||||
s.replace(pos1, n1, str, pos2);
|
||||
assert(s.__invariants());
|
||||
assert(pos1 <= old_size && pos2 <= str.size());
|
||||
assert(s == expected);
|
||||
typename S::size_type xlen = std::min(n1, old_size - pos1);
|
||||
typename S::size_type rlen = std::min(S::npos, str.size() - pos2);
|
||||
assert(s.size() == old_size - xlen + rlen);
|
||||
}
|
||||
catch (std::out_of_range&)
|
||||
{
|
||||
assert(pos1 > old_size || pos2 > str.size());
|
||||
assert(s == s0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template <class S>
|
||||
void test0()
|
||||
{
|
||||
@ -5796,6 +5823,24 @@ void test54()
|
||||
test(S("abcdefghijklmnopqrst"), 21, 0, S("12345678901234567890"), 21, 0, S("can't happen"));
|
||||
}
|
||||
|
||||
template <class S>
|
||||
void test55()
|
||||
{
|
||||
test_npos(S("abcdefghij"), 9, 1, S("12345678901234567890"), 10, S("abcdefghi1234567890"));
|
||||
test_npos(S("abcdefghij"), 9, 1, S("12345678901234567890"), 19, S("abcdefghi0"));
|
||||
test_npos(S("abcdefghij"), 9, 1, S("12345678901234567890"), 20, S("abcdefghi"));
|
||||
test_npos(S("abcdefghij"), 9, 1, S("12345678901234567890"), 20, S("abcdefghi"));
|
||||
test_npos(S("abcdefghij"), 9, 1, S("12345678901234567890"), 21, S("can't happen"));
|
||||
test_npos(S("abcdefghij"), 9, 2, S(""), 0, S("abcdefghi"));
|
||||
test_npos(S("abcdefghij"), 9, 2, S(""), 1, S("can't happen"));
|
||||
test_npos(S("abcdefghij"), 9, 2, S("12345"), 0, S("abcdefghi12345"));
|
||||
test_npos(S("abcdefghij"), 9, 2, S("12345"), 1, S("abcdefghi2345"));
|
||||
test_npos(S("abcdefghij"), 9, 2, S("12345"), 2, S("abcdefghi345"));
|
||||
test_npos(S("abcdefghij"), 9, 2, S("12345"), 4, S("abcdefghi5"));
|
||||
test_npos(S("abcdefghij"), 9, 2, S("12345"), 5, S("abcdefghi"));
|
||||
test_npos(S("abcdefghij"), 9, 2, S("12345"), 6, S("can't happen"));
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
@ -5855,6 +5900,7 @@ int main()
|
||||
test52<S>();
|
||||
test53<S>();
|
||||
test54<S>();
|
||||
test55<S>();
|
||||
}
|
||||
#if __cplusplus >= 201103L
|
||||
{
|
||||
@ -5914,6 +5960,7 @@ int main()
|
||||
test52<S>();
|
||||
test53<S>();
|
||||
test54<S>();
|
||||
test55<S>();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@ -10,7 +10,8 @@
|
||||
// <string>
|
||||
|
||||
// int compare(size_type pos1, size_type n1, const basic_string& str,
|
||||
// size_type pos2, size_type n2) const;
|
||||
// size_type pos2, size_type n2=npos) const;
|
||||
// the "=npos" was added in C++14
|
||||
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
@ -44,6 +45,23 @@ test(const S& s, typename S::size_type pos1, typename S::size_type n1,
|
||||
}
|
||||
}
|
||||
|
||||
template <class S>
|
||||
void
|
||||
test_npos(const S& s, typename S::size_type pos1, typename S::size_type n1,
|
||||
const S& str, typename S::size_type pos2, int x)
|
||||
{
|
||||
try
|
||||
{
|
||||
assert(sign(s.compare(pos1, n1, str, pos2)) == sign(x));
|
||||
assert(pos1 <= s.size());
|
||||
assert(pos2 <= str.size());
|
||||
}
|
||||
catch (std::out_of_range&)
|
||||
{
|
||||
assert(pos1 > s.size() || pos2 > str.size());
|
||||
}
|
||||
}
|
||||
|
||||
template <class S>
|
||||
void test0()
|
||||
{
|
||||
@ -5795,6 +5813,16 @@ void test54()
|
||||
test(S("abcdefghijklmnopqrst"), 21, 0, S("abcdefghijklmnopqrst"), 21, 0, 0);
|
||||
}
|
||||
|
||||
template<class S>
|
||||
void test55()
|
||||
{
|
||||
test_npos(S(""), 0, 0, S(""), 0, 0);
|
||||
test_npos(S(""), 0, 0, S("abcde"), 0, -5);
|
||||
test_npos(S("abcde"), 0, 0, S("abcdefghij"), 0, -10);
|
||||
test_npos(S("abcde"), 0, 0, S("abcdefghij"), 1, -9);
|
||||
test_npos(S("abcde"), 0, 0, S("abcdefghij"), 5, -5);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
@ -5854,6 +5882,7 @@ int main()
|
||||
test52<S>();
|
||||
test53<S>();
|
||||
test54<S>();
|
||||
test55<S>();
|
||||
}
|
||||
#if __cplusplus >= 201103L
|
||||
{
|
||||
@ -5913,6 +5942,7 @@ int main()
|
||||
test52<S>();
|
||||
test53<S>();
|
||||
test54<S>();
|
||||
test55<S>();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user