diff options
author | clyne <clyne@bitgloo.com> | 2020-06-26 18:11:57 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-26 18:11:57 -0400 |
commit | 84401c74731927a237ccd8e7b59444d3f0630664 (patch) | |
tree | a2c070e64c6a892ac2c54de301dd7293179c73b6 | |
parent | 8dfd9e49ad94f1e1d95deb16fcd2a794c7a7c72f (diff) |
Add support for range-based for loops
-rw-r--r-- | to_string.hpp | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/to_string.hpp b/to_string.hpp index 21b5f48..1d88b1a 100644 --- a/to_string.hpp +++ b/to_string.hpp @@ -43,19 +43,15 @@ struct to_string_t { } } - /** - * Allows implicit conversion of this object to a `char *`. - */ - constexpr operator char_type *() { - return buf; - } + // Support implicit casting to `char *` or `const char *`. + constexpr operator char_type *() { return buf; } + constexpr operator const char_type *() const { return buf; } - /** - * Allows implicit conversion of this object to a `const char *`. - */ - constexpr operator const char_type *() const { - return buf; - } + // Support range-based for loops + constexpr auto begin() { return buf; } + constexpr auto begin() const { return buf; } + constexpr auto end() { return buf + sizeof(buf) / sizeof(buf[0]); } + constexpr auto end() const { return buf + sizeof(buf) / sizeof(buf[0]); } }; /** |