Gobelijn API documentation  - generated for commit a0cbea7
 All Classes Namespaces Files Functions Variables Typedefs Friends Macros Pages
conststr.h
Go to the documentation of this file.
1 #pragma once
2 /*
3  * This file is part of the indismo software.
4  * It is free software: you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * any later version.
8  * The software is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  * You should have received a copy of the GNU General Public License
13  * along with the software. If not, see <http://www.gnu.org/licenses/>.
14  *
15  * Copyright 2014, L. Willem, J. Broeckhove, S. Stijven, UAntwerpen.
16  */
21 #include <stdexcept>
22 #include <string>
23 
24 class conststr
25 {
26 public:
27  template <std::size_t N>
28  constexpr conststr(const char (&a)[N]) : m_p(a), m_size(N - 1)
29  {
30  }
31 
32  // constexpr functions signal errors by throwing exceptions from operator ?:
33  constexpr char operator[](std::size_t n) const { return n < m_size ? m_p[n] : throw std::out_of_range(""); }
34 
35  constexpr std::size_t size() const { return m_size; }
36 
37  std::string to_string() const { return m_p; }
38 
39 private:
40  const char* m_p;
41  std::size_t m_size;
42 };
const char * m_p
Definition: conststr.h:40
std::size_t m_size
Definition: conststr.h:41
std::string to_string() const
Definition: conststr.h:37
constexpr char operator[](std::size_t n) const
Definition: conststr.h:33
constexpr std::size_t size() const
Definition: conststr.h:35
constexpr conststr(const char(&a)[N])
Definition: conststr.h:28