7#ifndef BOOST_LOCALE_DETAIL_ANY_STRING_HPP_INCLUDED
8#define BOOST_LOCALE_DETAIL_ANY_STRING_HPP_INCLUDED
10#include <boost/locale/config.hpp>
11#include <boost/assert.hpp>
12#include <boost/utility/string_view.hpp>
18namespace boost {
namespace locale {
namespace detail {
21 struct BOOST_SYMBOL_VISIBLE base {
22 virtual ~base() =
default;
23 virtual base* clone()
const = 0;
27 base(
const base&) =
default;
28 base(base&&) =
delete;
29 base& operator=(
const base&) =
default;
30 base& operator=(base&&) =
delete;
32 template<
typename Char>
33 struct BOOST_SYMBOL_VISIBLE impl : base {
34 explicit impl(
const boost::basic_string_view<Char> value) : s(value) {}
35 impl* clone()
const override {
return new impl(*
this); }
36 std::basic_string<Char> s;
39 std::unique_ptr<const base> s_;
42 any_string() =
default;
43 any_string(
const any_string& other) : s_(other.s_ ? other.s_->clone() : nullptr) {}
44 any_string(any_string&&) =
default;
45 any_string& operator=(any_string other)
51 template<
typename Char>
52 void set(
const boost::basic_string_view<Char> s)
54 BOOST_ASSERT(!s.empty());
55 s_.reset(
new impl<Char>(s));
58 template<
typename Char>
59 std::basic_string<Char> get()
const
62 throw std::bad_cast();
63 return dynamic_cast<const impl<Char>&
>(*s_).s;