Created
April 14, 2016 12:00
-
-
Save creative-quant/6aa863e1cb415cbb9056f3d86f23b2c4 to your computer and use it in GitHub Desktop.
str_const from Scott Schurr - 2012.cppnow.org -> schurr_cpp11_tools_for_class_authors.pdf
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
class str_const { // constexpr string | |
private: | |
const char* const p_; | |
const std::size_t sz_; | |
public: | |
template<std::size_t N> | |
constexpr str_const(const char (&a)[N]) : // ctor | |
p_(a), sz_(N - 1) { | |
} | |
constexpr char operator[](std::size_t n) { // [] | |
return n < sz_ ? p_[n] : throw std::out_of_range(""); | |
} | |
constexpr std::size_t size() { | |
return sz_; | |
} // size() | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment