diff --git a/include/boost/utility/string_view.hpp b/include/boost/utility/string_view.hpp index e3cb0ae..7f78a30 100644 --- a/include/boost/utility/string_view.hpp +++ b/include/boost/utility/string_view.hpp @@ -157,7 +157,7 @@ namespace boost { #ifndef BOOST_NO_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGS template > - std::basic_string to_string(const Allocator& a = Allocator()) const { + std::basic_string to_string(const Allocator& a = Allocator()) const { return std::basic_string(begin(), end(), a); } #else diff --git a/test/string_view_test2.cpp b/test/string_view_test2.cpp index be04231..971dee9 100644 --- a/test/string_view_test2.cpp +++ b/test/string_view_test2.cpp @@ -9,6 +9,9 @@ #include #include // for std::strchr +#ifndef BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS +#include // for std::malloc and std::free +#endif #include @@ -241,6 +244,29 @@ void find ( const char *arg ) { } +#ifndef BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS +template +class alloc_holder{ +public: + typedef T value_type; + explicit alloc_holder(){} + T *allocate(std::size_t n){ + return reinterpret_cast(std::malloc(sizeof(T) * n)); + } + void deallocate(T *p, std::size_t n){ + std::free(p); + } +}; + +template +bool operator==(const alloc_holder &, const alloc_holder &){ + return true; +} +template +bool operator!=(const alloc_holder &, const alloc_holder &){ + return false; +} +#endif void to_string ( const char *arg ) { string_view sr1; @@ -256,6 +282,8 @@ void to_string ( const char *arg ) { #ifndef BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS std::string str3 = static_cast ( sr1 ); BOOST_CHECK ( str1 == str3 ); + + std::basic_string, alloc_holder> alloc_str = sr1.to_string(alloc_holder()); #endif }