diff options
| author | Jonathan Wakely <jwakely@redhat.com> | 2015-01-20 11:50:51 +0000 |
|---|---|---|
| committer | Jonathan Wakely <redi@gcc.gnu.org> | 2015-01-20 11:50:51 +0000 |
| commit | 71a16cd8bcb8d112a2a1db544b7f3aa9cfea67f8 (patch) | |
| tree | b330b6dfc0fcea1b9f3d8f6ed8beee71add29a2c /libstdc++-v3/include | |
| parent | 0e4974d62ecd488122ae99b0b2ed5afeb1d121eb (diff) | |
Add C++11 std::string constructors for locales and facets.
* config/abi/pre/gnu.ver: Export new constructors.
* include/bits/codecvt.h (codecvt_byname): Add string constructor.
(codecvt_byname<char16_t>, codecvt_byname<char32_t>): Define explicit
specializations and declare explicit instantiations.
* include/bits/locale_classes.h (locale, collate_byname): Add string
constructors.
* include/bits/locale_facets.h (ctype_byname, numpunct_byname):
Likewise.
* include/bits/locale_facets_nonio.h (time_get_byname,
time_put_byname, moneypunct_byname, messages_byname): Likewise.
* src/c++11/codecvt.cc (codecvt_byname<char16_t>,
codecvt_byname<char32_t>): Define explicit instantiations.
* src/c++11/locale-inst.cc (time_put_byname, codecvt_byname):
Instantiate string constructors.
(ctype_byname): Define string constructor.
* testsuite/22_locale/codecvt_byname/1.cc: New.
* testsuite/22_locale/collate_byname/1.cc: New.
* testsuite/22_locale/ctype_byname/2.cc: New.
* testsuite/22_locale/messages_byname/1.cc: New.
* testsuite/22_locale/moneypunct_byname/1.cc: New.
* testsuite/22_locale/numpunct_byname/1.cc: New.
From-SVN: r219887
Diffstat (limited to 'libstdc++-v3/include')
| -rw-r--r-- | libstdc++-v3/include/bits/codecvt.h | 50 | ||||
| -rw-r--r-- | libstdc++-v3/include/bits/locale_classes.h | 34 | ||||
| -rw-r--r-- | libstdc++-v3/include/bits/locale_facets.h | 22 | ||||
| -rw-r--r-- | libstdc++-v3/include/bits/locale_facets_nonio.h | 24 |
4 files changed, 130 insertions, 0 deletions
diff --git a/libstdc++-v3/include/bits/codecvt.h b/libstdc++-v3/include/bits/codecvt.h index a6e59b5128f..c76215f87f5 100644 --- a/libstdc++-v3/include/bits/codecvt.h +++ b/libstdc++-v3/include/bits/codecvt.h @@ -594,11 +594,55 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } } +#if __cplusplus >= 201103L + explicit + codecvt_byname(const string& __s, size_t __refs = 0) + : codecvt_byname(__s.c_str(), __refs) { } +#endif + + protected: + virtual + ~codecvt_byname() { } + }; + +#if __cplusplus >= 201103L && defined(_GLIBCXX_USE_C99_STDINT_TR1) + template<> + class codecvt_byname<char16_t, char, mbstate_t> + : public codecvt<char16_t, char, mbstate_t> + { + public: + explicit + codecvt_byname(const char* __s, size_t __refs = 0) + : codecvt<char16_t, char, mbstate_t>(__refs) { } + + explicit + codecvt_byname(const string& __s, size_t __refs = 0) + : codecvt_byname(__s.c_str(), __refs) { } + protected: virtual ~codecvt_byname() { } }; + template<> + class codecvt_byname<char32_t, char, mbstate_t> + : public codecvt<char32_t, char, mbstate_t> + { + public: + explicit + codecvt_byname(const char* __s, size_t __refs = 0) + : codecvt<char32_t, char, mbstate_t>(__refs) { } + + explicit + codecvt_byname(const string& __s, size_t __refs = 0) + : codecvt_byname(__s.c_str(), __refs) { } + + protected: + virtual + ~codecvt_byname() { } + }; +#endif + // Inhibit implicit instantiations for required instantiations, // which are defined via explicit instantiations elsewhere. #if _GLIBCXX_EXTERN_TEMPLATE @@ -623,6 +667,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION bool has_facet<codecvt<wchar_t, char, mbstate_t> >(const locale&); #endif + +#if __cplusplus >= 201103L && defined(_GLIBCXX_USE_C99_STDINT_TR1) + extern template class codecvt_byname<char16_t, char, mbstate_t>; + extern template class codecvt_byname<char32_t, char, mbstate_t>; +#endif + #endif _GLIBCXX_END_NAMESPACE_VERSION diff --git a/libstdc++-v3/include/bits/locale_classes.h b/libstdc++-v3/include/bits/locale_classes.h index f591437f148..f3898ebf7b2 100644 --- a/libstdc++-v3/include/bits/locale_classes.h +++ b/libstdc++-v3/include/bits/locale_classes.h @@ -150,6 +150,34 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION */ locale(const locale& __base, const char* __s, category __cat); +#if __cplusplus >= 201103L + /** + * @brief Named locale constructor. + * + * Constructs a copy of the named C library locale. + * + * @param __s Name of the locale to construct. + * @throw std::runtime_error if __s is an undefined locale. + */ + explicit + locale(const std::string& __s) : locale(__s.c_str()) { } + + /** + * @brief Construct locale with facets from another locale. + * + * Constructs a copy of the locale @a base. The facets specified by @a + * cat are replaced with those from the locale named by @a s. If base is + * named, this locale instance will also be named. + * + * @param __base The locale to copy. + * @param __s Name of the locale to use facets from. + * @param __cat Set of categories defining the facets to use from __s. + * @throw std::runtime_error if __s is an undefined locale. + */ + locale(const locale& __base, const std::string& __s, category __cat) + : locale(__base, __s.c_str(), __cat) { } +#endif + /** * @brief Construct locale with facets from another locale. * @@ -797,6 +825,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } } +#if __cplusplus >= 201103L + explicit + collate_byname(const string& __s, size_t __refs = 0) + : collate_byname(__s.c_str(), __refs) { } +#endif + protected: virtual ~collate_byname() { } diff --git a/libstdc++-v3/include/bits/locale_facets.h b/libstdc++-v3/include/bits/locale_facets.h index 77932a5060b..0226b497c30 100644 --- a/libstdc++-v3/include/bits/locale_facets.h +++ b/libstdc++-v3/include/bits/locale_facets.h @@ -1479,6 +1479,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION explicit ctype_byname(const char* __s, size_t __refs = 0); +#if __cplusplus >= 201103L + explicit + ctype_byname(const string& __s, size_t __refs = 0) + : ctype_byname(__s.c_str(), __refs) { } +#endif + protected: virtual ~ctype_byname() { }; @@ -1492,6 +1498,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION explicit ctype_byname(const char* __s, size_t __refs = 0); +#if __cplusplus >= 201103L + explicit + ctype_byname(const string& __s, size_t __refs = 0); +#endif + protected: virtual ~ctype_byname(); @@ -1505,6 +1516,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION explicit ctype_byname(const char* __s, size_t __refs = 0); +#if __cplusplus >= 201103L + explicit + ctype_byname(const string& __s, size_t __refs = 0); +#endif + protected: virtual ~ctype_byname(); @@ -1900,6 +1916,12 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 } } +#if __cplusplus >= 201103L + explicit + numpunct_byname(const string& __s, size_t __refs = 0) + : numpunct_byname(__s.c_str(), __refs) { } +#endif + protected: virtual ~numpunct_byname() { } diff --git a/libstdc++-v3/include/bits/locale_facets_nonio.h b/libstdc++-v3/include/bits/locale_facets_nonio.h index 0c49880b0d3..7eae6c80653 100644 --- a/libstdc++-v3/include/bits/locale_facets_nonio.h +++ b/libstdc++-v3/include/bits/locale_facets_nonio.h @@ -766,6 +766,12 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 time_get_byname(const char*, size_t __refs = 0) : time_get<_CharT, _InIter>(__refs) { } +#if __cplusplus >= 201103L + explicit + time_get_byname(const string& __s, size_t __refs = 0) + : time_get_byname(__s.c_str(), __refs) { } +#endif + protected: virtual ~time_get_byname() { } @@ -894,6 +900,12 @@ _GLIBCXX_END_NAMESPACE_CXX11 : time_put<_CharT, _OutIter>(__refs) { }; +#if __cplusplus >= 201103L + explicit + time_put_byname(const string& __s, size_t __refs = 0) + : time_put_byname(__s.c_str(), __refs) { } +#endif + protected: virtual ~time_put_byname() { } @@ -1419,6 +1431,12 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 } } +#if __cplusplus >= 201103L + explicit + moneypunct_byname(const string& __s, size_t __refs = 0) + : moneypunct_byname(__s.c_str(), __refs) { } +#endif + protected: virtual ~moneypunct_byname() { } @@ -1969,6 +1987,12 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 explicit messages_byname(const char* __s, size_t __refs = 0); +#if __cplusplus >= 201103L + explicit + messages_byname(const string& __s, size_t __refs = 0) + : messages_byname(__s.c_str(), __refs) { } +#endif + protected: virtual ~messages_byname() |
