fix clang-5 build

This commit is contained in:
Neargye 2019-12-12 20:12:42 +05:00
parent ad59562c9e
commit f7554a166f
3 changed files with 39 additions and 7 deletions

View file

@ -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:

View file

@ -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)

View file

@ -94,6 +94,15 @@ class [[nodiscard]] cstring {
std::array<char, N + 1> 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<iterator>;
using const_reverse_iterator = std::reverse_iterator<const_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;