Skip to content

Instantly share code, notes, and snippets.

@m4h7
Last active June 19, 2024 09:46
Show Gist options
  • Select an option

  • Save m4h7/b8223899bef2a0e13e57955811af3d94 to your computer and use it in GitHub Desktop.

Select an option

Save m4h7/b8223899bef2a0e13e57955811af3d94 to your computer and use it in GitHub Desktop.

formatter:

template<>                                                  
struct std::formatter<Type> {
  constexpr auto parse(std::format_parse_context& context) { 
    return context.begin();
  }
  auto format(const Type& sVal, std::format_context& context) const {
    return std::format_to(context.out(), "{}", Type.getValue());
  }
};

via delegation:

template<>                                                      
struct std::formatter<T> {

    std::formatter<int> formatter;                               

    constexpr auto parse(std::format_parse_context& context) {
        return formatter.parse(context);                     
    }

    auto format(const SingleValue& singleValue, std::format_context& context) const {
        return formatter.format(singleValue.getValue(), context);
    }
}; 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment