diff --git a/.travis.yml b/.travis.yml index e200666..d2e5340 100644 --- a/.travis.yml +++ b/.travis.yml @@ -39,6 +39,34 @@ matrix: env: - CXX_COMPILER=g++-9 CC_COMPILER=gcc-9 + - os: linux + compiler: clang++ + addons: + apt: + sources: + - ubuntu-toolchain-r-test + - sourceline: 'deb https://apt.llvm.org/xenial/ llvm-toolchain-xenial-5 main' + key_url: 'https://apt.llvm.org/llvm-snapshot.gpg.key' + packages: + - g++-7 + - clang-5 + env: + - CXX_COMPILER=clang++-5 CC_COMPILER=clang-5 + + - os: linux + compiler: clang++ + addons: + apt: + sources: + - ubuntu-toolchain-r-test + - sourceline: 'deb https://apt.llvm.org/xenial/ llvm-toolchain-xenial-6 main' + key_url: 'https://apt.llvm.org/llvm-snapshot.gpg.key' + packages: + - g++-7 + - clang-6 + env: + - CXX_COMPILER=clang++-6 CC_COMPILER=clang-6 + - os: linux compiler: clang++ addons: diff --git a/README.md b/README.md index 83c70ad..c25bd84 100644 --- a/README.md +++ b/README.md @@ -113,7 +113,7 @@ If you are using [Conan](https://www.conan.io/) to manage your dependencies, mer ## Compiler compatibility -* Clang/LLVM >= 7 +* Clang/LLVM >= 5 * Visual C++ >= 15.3 / Visual Studio >= 2017 * Xcode >= 10 * GCC >= 7 (GCC >= 9 for NAMEOF_ENUM) diff --git a/include/nameof.hpp b/include/nameof.hpp index e6fbc74..abdad34 100644 --- a/include/nameof.hpp +++ b/include/nameof.hpp @@ -94,6 +94,15 @@ class [[nodiscard]] cstring { std::array chars_; + constexpr auto to_chars(std::string_view str) noexcept { + assert(str.size() == N); + decltype(chars_) chars = {}; + for (std::size_t i = 0; i < str.size() && i < N; ++i) { + chars[i] = str[i]; + } + return chars; + } + public: using value_type = char; using size_type = std::size_t; @@ -109,12 +118,7 @@ class [[nodiscard]] cstring { using reverse_iterator = std::reverse_iterator; using const_reverse_iterator = std::reverse_iterator; - constexpr explicit cstring(std::string_view str) noexcept : chars_{} { - assert(str.size() == N); - for (std::size_t i = 0; i < N; ++i) { - chars_[i] = str[i]; - } - } + constexpr explicit cstring(std::string_view str) noexcept : chars_{to_chars(str)} {} constexpr cstring() = delete;