summaryrefslogtreecommitdiffstats
path: root/libcxx/test/strings/basic.string/string.modifiers/string_assign
diff options
context:
space:
mode:
authorMarshall Clow <mclow.lists@gmail.com>2014-03-04 19:17:19 +0000
committerMarshall Clow <mclow.lists@gmail.com>2014-03-04 19:17:19 +0000
commit53b88dad6f5e54ad443ef428b1e1dfcea8f7f3d9 (patch)
tree33715cefc61657271056321c505d163f1f83775f /libcxx/test/strings/basic.string/string.modifiers/string_assign
parent5aa88fe1e7baf087dbff0f8b6dbd517832576fec (diff)
downloadbcm5719-llvm-53b88dad6f5e54ad443ef428b1e1dfcea8f7f3d9.tar.gz
bcm5719-llvm-53b88dad6f5e54ad443ef428b1e1dfcea8f7f3d9.zip
Implement LWG #2268: Setting a default argument in the declaration of a member function assign of std::basic_string.
llvm-svn: 202876
Diffstat (limited to 'libcxx/test/strings/basic.string/string.modifiers/string_assign')
-rw-r--r--libcxx/test/strings/basic.string/string.modifiers/string_assign/string_size_size.pass.cpp30
1 files changed, 29 insertions, 1 deletions
diff --git a/libcxx/test/strings/basic.string/string.modifiers/string_assign/string_size_size.pass.cpp b/libcxx/test/strings/basic.string/string.modifiers/string_assign/string_size_size.pass.cpp
index 116673cc4dd..5f5983e76c9 100644
--- a/libcxx/test/strings/basic.string/string.modifiers/string_assign/string_size_size.pass.cpp
+++ b/libcxx/test/strings/basic.string/string.modifiers/string_assign/string_size_size.pass.cpp
@@ -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"));
+ }
}
OpenPOWER on IntegriCloud