xref: /minix3/external/bsd/libc++/dist/libcxx/test/strings/basic.string/string.access/at.pass.cpp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
14684ddb6SLionel Sambuc //===----------------------------------------------------------------------===//
24684ddb6SLionel Sambuc //
34684ddb6SLionel Sambuc //                     The LLVM Compiler Infrastructure
44684ddb6SLionel Sambuc //
54684ddb6SLionel Sambuc // This file is dual licensed under the MIT and the University of Illinois Open
64684ddb6SLionel Sambuc // Source Licenses. See LICENSE.TXT for details.
74684ddb6SLionel Sambuc //
84684ddb6SLionel Sambuc //===----------------------------------------------------------------------===//
94684ddb6SLionel Sambuc 
104684ddb6SLionel Sambuc // <string>
114684ddb6SLionel Sambuc 
124684ddb6SLionel Sambuc // const_reference at(size_type pos) const;
134684ddb6SLionel Sambuc //       reference at(size_type pos);
144684ddb6SLionel Sambuc 
154684ddb6SLionel Sambuc #include <string>
164684ddb6SLionel Sambuc #include <stdexcept>
174684ddb6SLionel Sambuc #include <cassert>
184684ddb6SLionel Sambuc 
19*0a6a1f1dSLionel Sambuc #include "min_allocator.h"
204684ddb6SLionel Sambuc 
214684ddb6SLionel Sambuc template <class S>
224684ddb6SLionel Sambuc void
test(S s,typename S::size_type pos)234684ddb6SLionel Sambuc test(S s, typename S::size_type pos)
244684ddb6SLionel Sambuc {
254684ddb6SLionel Sambuc     try
264684ddb6SLionel Sambuc     {
274684ddb6SLionel Sambuc         const S& cs = s;
284684ddb6SLionel Sambuc         assert(s.at(pos) == s[pos]);
294684ddb6SLionel Sambuc         assert(cs.at(pos) == cs[pos]);
304684ddb6SLionel Sambuc         assert(pos < cs.size());
314684ddb6SLionel Sambuc     }
324684ddb6SLionel Sambuc     catch (std::out_of_range&)
334684ddb6SLionel Sambuc     {
344684ddb6SLionel Sambuc         assert(pos >= s.size());
354684ddb6SLionel Sambuc     }
364684ddb6SLionel Sambuc }
374684ddb6SLionel Sambuc 
main()384684ddb6SLionel Sambuc int main()
394684ddb6SLionel Sambuc {
404684ddb6SLionel Sambuc     {
414684ddb6SLionel Sambuc     typedef std::string S;
424684ddb6SLionel Sambuc     test(S(), 0);
434684ddb6SLionel Sambuc     test(S("123"), 0);
444684ddb6SLionel Sambuc     test(S("123"), 1);
454684ddb6SLionel Sambuc     test(S("123"), 2);
464684ddb6SLionel Sambuc     test(S("123"), 3);
474684ddb6SLionel Sambuc     }
484684ddb6SLionel Sambuc #if __cplusplus >= 201103L
494684ddb6SLionel Sambuc     {
504684ddb6SLionel Sambuc     typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
514684ddb6SLionel Sambuc     test(S(), 0);
524684ddb6SLionel Sambuc     test(S("123"), 0);
534684ddb6SLionel Sambuc     test(S("123"), 1);
544684ddb6SLionel Sambuc     test(S("123"), 2);
554684ddb6SLionel Sambuc     test(S("123"), 3);
564684ddb6SLionel Sambuc     }
574684ddb6SLionel Sambuc #endif
584684ddb6SLionel Sambuc }
59