Created
August 12, 2014 19:01
-
-
Save Enelar/67898ee001dbe98d92c4 to your computer and use it in GitHub Desktop.
Simple constexpression string container
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Introduced by Scott Schurr in "C++ Now! 2012" | |
class constexpr_string | |
{ | |
protected: | |
const char* const p; | |
const std::size_t s; | |
public: | |
template<std::size_t N> | |
constexpr constexpr_string(const char(&a)[N]) | |
: p(a), s(N-1) | |
{} | |
constexpr char operator[](std::size_t n) | |
{ | |
return n < s ? p[n] : throw std::out_of_range(""); | |
} | |
constexpr std::size_t size() | |
{ | |
return s; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment