format: allow implicit conversion from formats to strings

This commit is contained in:
Danny Robson 2018-11-29 13:10:02 +11:00
parent c7cc0dbf4c
commit ce3e3d83d3

View File

@ -115,6 +115,21 @@ namespace cruft::format {
}; };
template <typename... ValueT>
class bound;
template <typename ...Args>
std::string
to_string (const bound<Args...>&);
template <typename... ValueT>
class stored;
template <typename ...Args>
std::string
to_string (const bound<Args...>&);
/// parameter collection for a non-owning sequence of specifiers /// parameter collection for a non-owning sequence of specifiers
template <typename ...ValueT> template <typename ...ValueT>
class bound { class bound {
@ -124,13 +139,21 @@ namespace cruft::format {
m_values {args...} m_values {args...}
{ ; } { ; }
auto specifiers (void) const auto specifiers (void) const
{ return view (m_parsed.m_specifiers); } { return view (m_parsed.m_specifiers); }
template <size_t Index> template <size_t Index>
auto auto
get (void) const& { return std::get<Index> (m_values); } get (void) const& { return std::get<Index> (m_values); }
operator ::std::string () const
{
return to_string (*this);
}
private: private:
const parsed &m_parsed; const parsed &m_parsed;
std::tuple<const ValueT&...> m_values; std::tuple<const ValueT&...> m_values;
@ -146,16 +169,24 @@ namespace cruft::format {
m_values {args...} m_values {args...}
{ ; } { ; }
auto auto
specifiers (void) const& specifiers (void) const&
{ {
return view {m_specifiers}; return view {m_specifiers};
} }
template <size_t Index> template <size_t Index>
const auto& const auto&
get (void) const& { return std::get<Index> (m_values); } get (void) const& { return std::get<Index> (m_values); }
operator ::std::string () const
{
return to_string (*this);
}
private: private:
std::vector<specifier> m_specifiers; std::vector<specifier> m_specifiers;
std::tuple<const ValueT&...> m_values; std::tuple<const ValueT&...> m_values;