Skip to content

Instantly share code, notes, and snippets.

@creative-quant
Created April 14, 2016 12:00
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save creative-quant/6aa863e1cb415cbb9056f3d86f23b2c4 to your computer and use it in GitHub Desktop.
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
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