| 
									
										
										
										
											2015-12-21 11:39:59 -08:00
										 |  |  | /*
 | 
					
						
							|  |  |  |    Copyright (c) Marshall Clow 2012-2012. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |    Distributed under the Boost Software License, Version 1.0. (See accompanying | 
					
						
							|  |  |  |    file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     For more information, see http://www.boost.org
 | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-01 22:42:29 +03:00
										 |  |  | #include <new>        // for placement new
 | 
					
						
							| 
									
										
										
										
											2015-12-21 11:39:59 -08:00
										 |  |  | #include <iostream>
 | 
					
						
							| 
									
										
										
										
											2016-09-01 22:42:29 +03:00
										 |  |  | #include <cstddef>    // for NULL, std::size_t, std::ptrdiff_t
 | 
					
						
							|  |  |  | #include <cstring>    // for std::strchr and std::strcmp
 | 
					
						
							| 
									
										
										
										
											2016-08-26 02:15:11 +00:00
										 |  |  | #include <cstdlib>    // for std::malloc and std::free
 | 
					
						
							| 
									
										
										
										
											2015-12-21 11:39:59 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include <boost/utility/string_view.hpp>
 | 
					
						
							| 
									
										
										
										
											2016-09-01 22:42:29 +03:00
										 |  |  | #include <boost/config.hpp>
 | 
					
						
							| 
									
										
										
										
											2015-12-21 11:39:59 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-23 12:58:39 -05:00
										 |  |  | #include <boost/core/lightweight_test.hpp>
 | 
					
						
							| 
									
										
										
										
											2015-12-21 11:39:59 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | typedef boost::string_view string_view; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ends_with ( const char *arg ) { | 
					
						
							|  |  |  |     const size_t sz = std::strlen ( arg ); | 
					
						
							|  |  |  |     string_view sr ( arg ); | 
					
						
							|  |  |  |     string_view sr2 ( arg ); | 
					
						
							|  |  |  |     const char *p = arg; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     while ( *p ) { | 
					
						
							| 
									
										
										
										
											2017-12-23 12:58:39 -05:00
										 |  |  |         BOOST_TEST ( sr.ends_with ( p )); | 
					
						
							| 
									
										
										
										
											2015-12-21 11:39:59 -08:00
										 |  |  |         ++p; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     while ( !sr2.empty ()) { | 
					
						
							| 
									
										
										
										
											2017-12-23 12:58:39 -05:00
										 |  |  |         BOOST_TEST ( sr.ends_with ( sr2 )); | 
					
						
							| 
									
										
										
										
											2015-12-21 11:39:59 -08:00
										 |  |  |         sr2.remove_prefix (1); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     sr2 = arg; | 
					
						
							|  |  |  |     while ( !sr2.empty ()) { | 
					
						
							| 
									
										
										
										
											2017-12-23 12:58:39 -05:00
										 |  |  |         BOOST_TEST ( sr.ends_with ( sr2 )); | 
					
						
							| 
									
										
										
										
											2015-12-21 11:39:59 -08:00
										 |  |  |         sr2.remove_prefix (1); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     char ch = sz == 0 ? '\0' : arg [ sz - 1 ]; | 
					
						
							|  |  |  |     sr2 = arg; | 
					
						
							|  |  |  |     if ( sz > 0 ) | 
					
						
							| 
									
										
										
										
											2017-12-23 12:58:39 -05:00
										 |  |  |       BOOST_TEST ( sr2.ends_with ( ch )); | 
					
						
							|  |  |  |     BOOST_TEST ( !sr2.ends_with ( ++ch )); | 
					
						
							|  |  |  |     BOOST_TEST ( sr2.ends_with ( string_view())); | 
					
						
							| 
									
										
										
										
											2015-12-21 11:39:59 -08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void starts_with ( const char *arg ) { | 
					
						
							|  |  |  |     const size_t sz = std::strlen ( arg ); | 
					
						
							|  |  |  |     string_view sr  ( arg ); | 
					
						
							|  |  |  |     string_view sr2 ( arg ); | 
					
						
							|  |  |  |     const char *p = arg + std::strlen ( arg ) - 1; | 
					
						
							|  |  |  |     while ( p >= arg ) { | 
					
						
							|  |  |  |         std::string foo ( arg, p + 1 ); | 
					
						
							| 
									
										
										
										
											2017-12-23 12:58:39 -05:00
										 |  |  |         BOOST_TEST ( sr.starts_with ( foo )); | 
					
						
							| 
									
										
										
										
											2015-12-21 11:39:59 -08:00
										 |  |  |         --p; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     while ( !sr2.empty ()) { | 
					
						
							| 
									
										
										
										
											2017-12-23 12:58:39 -05:00
										 |  |  |         BOOST_TEST ( sr.starts_with ( sr2 )); | 
					
						
							| 
									
										
										
										
											2015-12-21 11:39:59 -08:00
										 |  |  |         sr2.remove_suffix (1); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     char ch = *arg; | 
					
						
							|  |  |  |     sr2 = arg; | 
					
						
							|  |  |  |   if ( sz > 0 ) | 
					
						
							| 
									
										
										
										
											2017-12-23 12:58:39 -05:00
										 |  |  |     BOOST_TEST ( sr2.starts_with ( ch )); | 
					
						
							|  |  |  |     BOOST_TEST ( !sr2.starts_with ( ++ch )); | 
					
						
							|  |  |  |     BOOST_TEST ( sr2.starts_with ( string_view ())); | 
					
						
							| 
									
										
										
										
											2015-12-21 11:39:59 -08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void reverse ( const char *arg ) { | 
					
						
							|  |  |  | //  Round trip
 | 
					
						
							|  |  |  |     string_view sr1 ( arg ); | 
					
						
							|  |  |  |     std::string string1 ( sr1.rbegin (), sr1.rend ()); | 
					
						
							|  |  |  |     string_view sr2 ( string1 ); | 
					
						
							|  |  |  |     std::string string2 ( sr2.rbegin (), sr2.rend ()); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-23 12:58:39 -05:00
										 |  |  |     BOOST_TEST ( std::equal ( sr2.rbegin (), sr2.rend (), arg )); | 
					
						
							|  |  |  |     BOOST_TEST ( string2 == arg ); | 
					
						
							|  |  |  |     BOOST_TEST ( std::equal ( sr1.begin (), sr1.end (), string2.begin ())); | 
					
						
							| 
									
										
										
										
											2015-12-21 11:39:59 -08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-01 22:42:29 +03:00
										 |  |  | //  This helper function eliminates signed vs. unsigned warnings
 | 
					
						
							| 
									
										
										
										
											2015-12-21 11:39:59 -08:00
										 |  |  | string_view::size_type ptr_diff ( const char *res, const char *base ) { | 
					
						
							| 
									
										
										
										
											2017-12-23 12:58:39 -05:00
										 |  |  |     BOOST_TEST ( res >= base ); | 
					
						
							| 
									
										
										
										
											2015-12-21 11:39:59 -08:00
										 |  |  |     return static_cast<string_view::size_type> ( res - base ); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void find ( const char *arg ) { | 
					
						
							|  |  |  |     string_view sr1; | 
					
						
							|  |  |  |     string_view sr2; | 
					
						
							|  |  |  |     const char *p; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | //  Look for each character in the string(searching from the start)
 | 
					
						
							|  |  |  |     p = arg; | 
					
						
							|  |  |  |     sr1 = arg; | 
					
						
							|  |  |  |     while ( *p ) { | 
					
						
							|  |  |  |       string_view::size_type pos = sr1.find(*p); | 
					
						
							| 
									
										
										
										
											2017-12-23 12:58:39 -05:00
										 |  |  |       BOOST_TEST ( pos != string_view::npos && ( pos <= ptr_diff ( p, arg ))); | 
					
						
							| 
									
										
										
										
											2015-12-21 11:39:59 -08:00
										 |  |  |       ++p; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | //  Look for each character in the string (searching from the end)
 | 
					
						
							|  |  |  |     p = arg; | 
					
						
							|  |  |  |     sr1 = arg; | 
					
						
							|  |  |  |     while ( *p ) { | 
					
						
							|  |  |  |       string_view::size_type pos = sr1.rfind(*p); | 
					
						
							| 
									
										
										
										
											2017-12-23 12:58:39 -05:00
										 |  |  |       BOOST_TEST ( pos != string_view::npos && pos < sr1.size () && ( pos >= ptr_diff ( p, arg ))); | 
					
						
							| 
									
										
										
										
											2015-12-21 11:39:59 -08:00
										 |  |  |       ++p; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-01 22:42:29 +03:00
										 |  |  | //  Look for pairs on characters (searching from the start)
 | 
					
						
							| 
									
										
										
										
											2015-12-21 11:39:59 -08:00
										 |  |  |     sr1 = arg; | 
					
						
							|  |  |  |     p = arg; | 
					
						
							|  |  |  |     while ( *p && *(p+1)) { | 
					
						
							|  |  |  |         string_view sr3 ( p, 2 ); | 
					
						
							|  |  |  |         string_view::size_type pos = sr1.find ( sr3 ); | 
					
						
							| 
									
										
										
										
											2017-12-23 12:58:39 -05:00
										 |  |  |         BOOST_TEST ( pos != string_view::npos && pos <= static_cast<string_view::size_type>( p - arg )); | 
					
						
							| 
									
										
										
										
											2015-12-21 11:39:59 -08:00
										 |  |  |         p++; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     sr1 = arg; | 
					
						
							|  |  |  |     p = arg; | 
					
						
							|  |  |  | //  for all possible chars, see if we find them in the right place.
 | 
					
						
							|  |  |  | //  Note that strchr will/might do the _wrong_ thing if we search for NULL
 | 
					
						
							|  |  |  |     for ( int ch = 1; ch < 256; ++ch ) { | 
					
						
							|  |  |  |         string_view::size_type pos = sr1.find(ch); | 
					
						
							|  |  |  |         const char *strp = std::strchr ( arg, ch ); | 
					
						
							| 
									
										
										
										
											2017-12-23 12:58:39 -05:00
										 |  |  |         BOOST_TEST (( strp == NULL ) == ( pos == string_view::npos )); | 
					
						
							| 
									
										
										
										
											2015-12-21 11:39:59 -08:00
										 |  |  |         if ( strp != NULL ) | 
					
						
							| 
									
										
										
										
											2017-12-23 12:58:39 -05:00
										 |  |  |             BOOST_TEST ( ptr_diff ( strp, arg ) == pos ); | 
					
						
							| 
									
										
										
										
											2015-12-21 11:39:59 -08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     sr1 = arg; | 
					
						
							|  |  |  |     p = arg; | 
					
						
							|  |  |  | //  for all possible chars, see if we find them in the right place.
 | 
					
						
							|  |  |  | //  Note that strchr will/might do the _wrong_ thing if we search for NULL
 | 
					
						
							|  |  |  |     for ( int ch = 1; ch < 256; ++ch ) { | 
					
						
							|  |  |  |         string_view::size_type pos = sr1.rfind(ch); | 
					
						
							|  |  |  |         const char *strp = std::strrchr ( arg, ch ); | 
					
						
							| 
									
										
										
										
											2017-12-23 12:58:39 -05:00
										 |  |  |         BOOST_TEST (( strp == NULL ) == ( pos == string_view::npos )); | 
					
						
							| 
									
										
										
										
											2015-12-21 11:39:59 -08:00
										 |  |  |         if ( strp != NULL ) | 
					
						
							| 
									
										
										
										
											2017-12-23 12:58:39 -05:00
										 |  |  |             BOOST_TEST ( ptr_diff ( strp, arg ) == pos ); | 
					
						
							| 
									
										
										
										
											2015-12-21 11:39:59 -08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | //  Find everything at the start
 | 
					
						
							|  |  |  |     p = arg; | 
					
						
							|  |  |  |     sr1 = arg; | 
					
						
							|  |  |  |     while ( !sr1.empty ()) { | 
					
						
							|  |  |  |         string_view::size_type pos = sr1.find(*p); | 
					
						
							| 
									
										
										
										
											2017-12-23 12:58:39 -05:00
										 |  |  |         BOOST_TEST ( pos == 0 ); | 
					
						
							| 
									
										
										
										
											2015-12-21 11:39:59 -08:00
										 |  |  |         sr1.remove_prefix (1); | 
					
						
							|  |  |  |         ++p; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | //  Find everything at the end
 | 
					
						
							|  |  |  |     sr1  = arg; | 
					
						
							|  |  |  |     p    = arg + std::strlen ( arg ) - 1; | 
					
						
							|  |  |  |     while ( !sr1.empty ()) { | 
					
						
							|  |  |  |         string_view::size_type pos = sr1.rfind(*p); | 
					
						
							| 
									
										
										
										
											2017-12-23 12:58:39 -05:00
										 |  |  |         BOOST_TEST ( pos == sr1.size () - 1 ); | 
					
						
							| 
									
										
										
										
											2015-12-21 11:39:59 -08:00
										 |  |  |         sr1.remove_suffix (1); | 
					
						
							|  |  |  |         --p; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | //  Find everything at the start
 | 
					
						
							|  |  |  |     sr1  = arg; | 
					
						
							|  |  |  |     p    = arg; | 
					
						
							|  |  |  |     while ( !sr1.empty ()) { | 
					
						
							|  |  |  |         string_view::size_type pos = sr1.find_first_of(*p); | 
					
						
							| 
									
										
										
										
											2017-12-23 12:58:39 -05:00
										 |  |  |         BOOST_TEST ( pos == 0 ); | 
					
						
							| 
									
										
										
										
											2015-12-21 11:39:59 -08:00
										 |  |  |         sr1.remove_prefix (1); | 
					
						
							|  |  |  |         ++p; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | //  Find everything at the end
 | 
					
						
							|  |  |  |     sr1  = arg; | 
					
						
							|  |  |  |     p    = arg + std::strlen ( arg ) - 1; | 
					
						
							|  |  |  |     while ( !sr1.empty ()) { | 
					
						
							|  |  |  |         string_view::size_type pos = sr1.find_last_of(*p); | 
					
						
							| 
									
										
										
										
											2017-12-23 12:58:39 -05:00
										 |  |  |         BOOST_TEST ( pos == sr1.size () - 1 ); | 
					
						
							| 
									
										
										
										
											2015-12-21 11:39:59 -08:00
										 |  |  |         sr1.remove_suffix (1); | 
					
						
							|  |  |  |         --p; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | //  Basic sanity checking for "find_first_of / find_first_not_of"
 | 
					
						
							|  |  |  |     sr1 = arg; | 
					
						
							|  |  |  |     sr2 = arg; | 
					
						
							|  |  |  |     while ( !sr1.empty() ) { | 
					
						
							| 
									
										
										
										
											2017-12-23 12:58:39 -05:00
										 |  |  |         BOOST_TEST ( sr1.find_first_of ( sr2 )     == 0 ); | 
					
						
							|  |  |  |         BOOST_TEST ( sr1.find_first_not_of ( sr2 ) == string_view::npos ); | 
					
						
							| 
									
										
										
										
											2015-12-21 11:39:59 -08:00
										 |  |  |         sr1.remove_prefix ( 1 ); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     p = arg; | 
					
						
							|  |  |  |     sr1 = arg; | 
					
						
							|  |  |  |     while ( *p ) { | 
					
						
							|  |  |  |         string_view::size_type pos1 = sr1.find_first_of(*p); | 
					
						
							|  |  |  |         string_view::size_type pos2 = sr1.find_first_not_of(*p); | 
					
						
							| 
									
										
										
										
											2017-12-23 12:58:39 -05:00
										 |  |  |         BOOST_TEST ( pos1 != string_view::npos && pos1 < sr1.size () && pos1 <= ptr_diff ( p, arg )); | 
					
						
							| 
									
										
										
										
											2015-12-21 11:39:59 -08:00
										 |  |  |         if ( pos2 != string_view::npos ) { | 
					
						
							|  |  |  |             for ( size_t i = 0 ; i < pos2; ++i ) | 
					
						
							| 
									
										
										
										
											2017-12-23 12:58:39 -05:00
										 |  |  |                 BOOST_TEST ( sr1[i] == *p ); | 
					
						
							|  |  |  |             BOOST_TEST ( sr1 [ pos2 ] != *p ); | 
					
						
							| 
									
										
										
										
											2015-12-21 11:39:59 -08:00
										 |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-23 12:58:39 -05:00
										 |  |  |         BOOST_TEST ( pos2 != pos1 ); | 
					
						
							| 
									
										
										
										
											2015-12-21 11:39:59 -08:00
										 |  |  |         ++p; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | //  Basic sanity checking for "find_last_of / find_last_not_of"
 | 
					
						
							|  |  |  |     sr1 = arg; | 
					
						
							|  |  |  |     sr2 = arg; | 
					
						
							|  |  |  |     while ( !sr1.empty() ) { | 
					
						
							| 
									
										
										
										
											2017-12-23 12:58:39 -05:00
										 |  |  |         BOOST_TEST ( sr1.find_last_of ( sr2 )     == ( sr1.size () - 1 )); | 
					
						
							|  |  |  |         BOOST_TEST ( sr1.find_last_not_of ( sr2 ) == string_view::npos ); | 
					
						
							| 
									
										
										
										
											2015-12-21 11:39:59 -08:00
										 |  |  |         sr1.remove_suffix ( 1 ); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     p = arg; | 
					
						
							|  |  |  |     sr1 = arg; | 
					
						
							|  |  |  |     while ( *p ) { | 
					
						
							|  |  |  |         string_view::size_type pos1 = sr1.find_last_of(*p); | 
					
						
							|  |  |  |         string_view::size_type pos2 = sr1.find_last_not_of(*p); | 
					
						
							| 
									
										
										
										
											2017-12-23 12:58:39 -05:00
										 |  |  |         BOOST_TEST ( pos1 != string_view::npos && pos1 < sr1.size () && pos1 >= ptr_diff ( p, arg )); | 
					
						
							|  |  |  |         BOOST_TEST ( pos2 == string_view::npos || pos1 < sr1.size ()); | 
					
						
							| 
									
										
										
										
											2015-12-21 11:39:59 -08:00
										 |  |  |         if ( pos2 != string_view::npos ) { | 
					
						
							|  |  |  |             for ( size_t i = sr1.size () -1 ; i > pos2; --i ) | 
					
						
							| 
									
										
										
										
											2017-12-23 12:58:39 -05:00
										 |  |  |                 BOOST_TEST ( sr1[i] == *p ); | 
					
						
							|  |  |  |             BOOST_TEST ( sr1 [ pos2 ] != *p ); | 
					
						
							| 
									
										
										
										
											2015-12-21 11:39:59 -08:00
										 |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-23 12:58:39 -05:00
										 |  |  |         BOOST_TEST ( pos2 != pos1 ); | 
					
						
							| 
									
										
										
										
											2015-12-21 11:39:59 -08:00
										 |  |  |         ++p; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-26 02:15:11 +00:00
										 |  |  | template <typename T> | 
					
						
							| 
									
										
										
										
											2016-09-01 22:42:29 +03:00
										 |  |  | class custom_allocator { | 
					
						
							| 
									
										
										
										
											2016-08-26 02:15:11 +00:00
										 |  |  | public: | 
					
						
							|  |  |  |     typedef T value_type; | 
					
						
							| 
									
										
										
										
											2016-09-01 22:42:29 +03:00
										 |  |  |     typedef T* pointer; | 
					
						
							|  |  |  |     typedef const T* const_pointer; | 
					
						
							|  |  |  |     typedef void* void_pointer; | 
					
						
							|  |  |  |     typedef const void* const_void_pointer; | 
					
						
							|  |  |  |     typedef std::size_t size_type; | 
					
						
							|  |  |  |     typedef std::ptrdiff_t difference_type; | 
					
						
							|  |  |  |     typedef T& reference; | 
					
						
							|  |  |  |     typedef const T& const_reference; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     template<class U> | 
					
						
							|  |  |  |     struct rebind { | 
					
						
							|  |  |  |         typedef custom_allocator<U> other; | 
					
						
							|  |  |  |         }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     custom_allocator() BOOST_NOEXCEPT {} | 
					
						
							|  |  |  |     template <typename U> | 
					
						
							|  |  |  |     custom_allocator(custom_allocator<U> const&) BOOST_NOEXCEPT {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     pointer allocate(size_type n) const { | 
					
						
							|  |  |  |         return static_cast<pointer>(std::malloc(sizeof(value_type) * n)); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     void deallocate(pointer p, size_type) const BOOST_NOEXCEPT { | 
					
						
							| 
									
										
										
										
											2016-08-26 02:15:11 +00:00
										 |  |  |         std::free(p); | 
					
						
							| 
									
										
										
										
											2016-09-01 22:42:29 +03:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     pointer address(reference value) const BOOST_NOEXCEPT { | 
					
						
							|  |  |  |         return &value; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const_pointer address(const_reference value) const BOOST_NOEXCEPT { | 
					
						
							|  |  |  |         return &value; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     BOOST_CONSTEXPR size_type max_size() const BOOST_NOEXCEPT { | 
					
						
							|  |  |  |         return (~(size_type)0u) / sizeof(value_type); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
 | 
					
						
							|  |  |  | #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
 | 
					
						
							|  |  |  |     template <class U, class... Args> | 
					
						
							|  |  |  |     void construct(U* ptr, Args&&... args) const { | 
					
						
							|  |  |  |         ::new((void*)ptr) U(static_cast<Args&&>(args)...); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  |     template <class U, class V> | 
					
						
							|  |  |  |     void construct(U* ptr, V&& value) const { | 
					
						
							|  |  |  |         ::new((void*)ptr) U(static_cast<V&&>(value)); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  |     template <class U, class V> | 
					
						
							|  |  |  |     void construct(U* ptr, const V& value) const { | 
					
						
							|  |  |  |         ::new((void*)ptr) U(value); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     template <class U> | 
					
						
							|  |  |  |     void construct(U* ptr) const { | 
					
						
							|  |  |  |         ::new((void*)ptr) U(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     template <class U> | 
					
						
							|  |  |  |     void destroy(U* ptr) const { | 
					
						
							|  |  |  |         (void)ptr; | 
					
						
							|  |  |  |         ptr->~U(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     }; | 
					
						
							| 
									
										
										
										
											2016-08-26 02:15:11 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | template <typename T, typename U> | 
					
						
							| 
									
										
										
										
											2016-09-01 22:42:29 +03:00
										 |  |  | BOOST_CONSTEXPR bool operator==(const custom_allocator<T> &, const custom_allocator<U> &) BOOST_NOEXCEPT { | 
					
						
							| 
									
										
										
										
											2016-08-26 02:15:11 +00:00
										 |  |  |     return true; | 
					
						
							| 
									
										
										
										
											2016-09-01 22:42:29 +03:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-08-26 02:15:11 +00:00
										 |  |  | template <typename T, typename U> | 
					
						
							| 
									
										
										
										
											2016-09-01 22:42:29 +03:00
										 |  |  | BOOST_CONSTEXPR bool operator!=(const custom_allocator<T> &, const custom_allocator<U> &) BOOST_NOEXCEPT { | 
					
						
							| 
									
										
										
										
											2016-08-26 02:15:11 +00:00
										 |  |  |     return false; | 
					
						
							| 
									
										
										
										
											2016-09-01 22:42:29 +03:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-12-21 11:39:59 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | void to_string ( const char *arg ) { | 
					
						
							|  |  |  |     string_view sr1; | 
					
						
							|  |  |  |     std::string str1; | 
					
						
							|  |  |  |     std::string str2; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     str1.assign ( arg ); | 
					
						
							|  |  |  |     sr1 = arg; | 
					
						
							| 
									
										
										
										
											2016-09-01 22:42:29 +03:00
										 |  |  | //  str2 = sr1.to_string<std::allocator<char> > ();
 | 
					
						
							| 
									
										
										
										
											2015-12-21 11:39:59 -08:00
										 |  |  |     str2 = sr1.to_string (); | 
					
						
							| 
									
										
										
										
											2017-12-23 12:58:39 -05:00
										 |  |  |     BOOST_TEST ( str1 == str2 ); | 
					
						
							| 
									
										
										
										
											2015-12-21 11:39:59 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-01 22:42:29 +03:00
										 |  |  |     std::basic_string<char, std::char_traits<char>, custom_allocator<char> > str3 = sr1.to_string(custom_allocator<char>()); | 
					
						
							| 
									
										
										
										
											2017-12-23 12:58:39 -05:00
										 |  |  |     BOOST_TEST ( std::strcmp(str1.c_str(), str3.c_str()) == 0 ); | 
					
						
							| 
									
										
										
										
											2016-08-26 02:15:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-01 22:42:29 +03:00
										 |  |  | #ifndef BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS
 | 
					
						
							|  |  |  |     std::string str4 = static_cast<std::string> ( sr1 ); | 
					
						
							| 
									
										
										
										
											2017-12-23 12:58:39 -05:00
										 |  |  |     BOOST_TEST ( str1 == str4 ); | 
					
						
							| 
									
										
										
										
											2015-12-21 11:39:59 -08:00
										 |  |  | #endif
 | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void compare ( const char *arg ) { | 
					
						
							|  |  |  |     string_view sr1; | 
					
						
							|  |  |  |     std::string str1; | 
					
						
							|  |  |  |     std::string str2 = str1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     str1.assign ( arg ); | 
					
						
							|  |  |  |     sr1 = arg; | 
					
						
							| 
									
										
										
										
											2017-12-23 12:58:39 -05:00
										 |  |  |     BOOST_TEST ( sr1  == sr1);    // compare string_view and string_view
 | 
					
						
							|  |  |  |     BOOST_TEST ( sr1  == str1);   // compare string and string_view
 | 
					
						
							|  |  |  |     BOOST_TEST ( str1 == sr1 );   // compare string_view and string
 | 
					
						
							|  |  |  |     BOOST_TEST ( sr1  == arg );   // compare string_view and pointer
 | 
					
						
							|  |  |  |     BOOST_TEST ( arg  == sr1 );   // compare pointer and string_view
 | 
					
						
							| 
									
										
										
										
											2015-12-21 11:39:59 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if ( sr1.size () > 0 ) { | 
					
						
							|  |  |  |         (*str1.rbegin())++; | 
					
						
							| 
									
										
										
										
											2017-12-23 12:58:39 -05:00
										 |  |  |         BOOST_TEST ( sr1  != str1 ); | 
					
						
							|  |  |  |         BOOST_TEST ( str1 != sr1 ); | 
					
						
							|  |  |  |         BOOST_TEST ( sr1 < str1 ); | 
					
						
							|  |  |  |         BOOST_TEST ( sr1 <= str1 ); | 
					
						
							|  |  |  |         BOOST_TEST ( str1 > sr1 ); | 
					
						
							|  |  |  |         BOOST_TEST ( str1 >= sr1 ); | 
					
						
							| 
									
										
										
										
											2015-12-21 11:39:59 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         (*str1.rbegin()) -= 2; | 
					
						
							| 
									
										
										
										
											2017-12-23 12:58:39 -05:00
										 |  |  |         BOOST_TEST ( sr1  != str1 ); | 
					
						
							|  |  |  |         BOOST_TEST ( str1 != sr1 ); | 
					
						
							|  |  |  |         BOOST_TEST ( sr1 > str1 ); | 
					
						
							|  |  |  |         BOOST_TEST ( sr1 >= str1 ); | 
					
						
							|  |  |  |         BOOST_TEST ( str1 < sr1 ); | 
					
						
							|  |  |  |         BOOST_TEST ( str1 <= sr1 ); | 
					
						
							| 
									
										
										
										
											2015-12-21 11:39:59 -08:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const char *test_strings [] = { | 
					
						
							|  |  |  |     "", | 
					
						
							|  |  |  |     "0", | 
					
						
							|  |  |  |     "abc", | 
					
						
							|  |  |  |     "AAA",  // all the same
 | 
					
						
							|  |  |  |     "adsfadadiaef;alkdg;aljt;j agl;sjrl;tjs;lga;lretj;srg[w349u5209dsfadfasdfasdfadsf", | 
					
						
							|  |  |  |     "abc\0asdfadsfasf", | 
					
						
							|  |  |  |     NULL | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-23 12:58:39 -05:00
										 |  |  | int main() | 
					
						
							| 
									
										
										
										
											2015-12-21 11:39:59 -08:00
										 |  |  | { | 
					
						
							|  |  |  |     const char **p = &test_strings[0]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     while ( *p != NULL ) { | 
					
						
							|  |  |  |         starts_with ( *p ); | 
					
						
							|  |  |  |         ends_with ( *p ); | 
					
						
							|  |  |  |         reverse ( *p ); | 
					
						
							|  |  |  |         find ( *p ); | 
					
						
							|  |  |  |         to_string ( *p ); | 
					
						
							|  |  |  |         compare ( *p ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         p++; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-12-23 12:58:39 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     return boost::report_errors(); | 
					
						
							| 
									
										
										
										
											2015-12-21 11:39:59 -08:00
										 |  |  | } |