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
template <typename ...ValueT>
class bound {
@ -124,13 +139,21 @@ namespace cruft::format {
m_values {args...}
{ ; }
auto specifiers (void) const
{ return view (m_parsed.m_specifiers); }
template <size_t Index>
auto
get (void) const& { return std::get<Index> (m_values); }
operator ::std::string () const
{
return to_string (*this);
}
private:
const parsed &m_parsed;
std::tuple<const ValueT&...> m_values;
@ -146,16 +169,24 @@ namespace cruft::format {
m_values {args...}
{ ; }
auto
specifiers (void) const&
{
return view {m_specifiers};
}
template <size_t Index>
const auto&
get (void) const& { return std::get<Index> (m_values); }
operator ::std::string () const
{
return to_string (*this);
}
private:
std::vector<specifier> m_specifiers;
std::tuple<const ValueT&...> m_values;