clean-up
This commit is contained in:
parent
d1dddd8758
commit
654c74d5db
3 changed files with 10 additions and 13 deletions
|
@ -7,8 +7,8 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
|
||||
if((CMAKE_CXX_COMPILER_ID MATCHES "GNU") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
|
||||
add_compile_options(-stdlib=libc++)
|
||||
add_compile_options(-Wall -Wextra -pedantic-errors)
|
||||
set(CMAKE_VERBOSE_MAKEFILE ON)
|
||||
elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
|
||||
add_compile_options(/W4)
|
||||
check_cxx_compiler_flag(/permissive HAS_PERMISSIVE_FLAG)
|
||||
|
|
|
@ -86,7 +86,7 @@ int main() {
|
|||
#if (__cplusplus >= 201402L || (defined(_MSVC_LANG) && _MSC_VER >= 1910 && _MSVC_LANG >= 201402L))
|
||||
// Compile-time supported by C++14.
|
||||
constexpr auto constexpr_work_fine = NAMEOF(somevar);
|
||||
std::cout << constexpr_work_fine << std::endl; // somevar
|
||||
static_assert(constexpr_work_fine == "somevar", "");
|
||||
#endif
|
||||
|
||||
// Enum name.
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
|
||||
#include <cstddef>
|
||||
#include <type_traits>
|
||||
#include <limits>
|
||||
#include <string>
|
||||
#include <ostream>
|
||||
|
||||
#if (__cplusplus >= 201402L || (defined(_MSVC_LANG) && _MSC_VER >= 1910 && _MSVC_LANG >= 201402L))
|
||||
|
@ -59,6 +59,10 @@ struct remove_all_pointers
|
|||
template <typename T>
|
||||
using Decay = std::remove_reference<typename std::remove_cv<typename remove_all_pointers<T>::type>::type>;
|
||||
|
||||
inline constexpr bool StrEquals(const char* lhs, const char* rhs, std::size_t size) {
|
||||
return size == 0 ? (lhs[0] == rhs[0]) : ((lhs[size - 1] == rhs[size - 1]) && StrEquals(lhs, rhs, size - 1));
|
||||
}
|
||||
|
||||
// STD like compile-time string.
|
||||
class cstring final {
|
||||
const char* str_;
|
||||
|
@ -83,8 +87,6 @@ class cstring final {
|
|||
|
||||
inline constexpr std::size_t length() const noexcept { return size_; }
|
||||
|
||||
inline constexpr std::size_t max_size() const noexcept { return std::numeric_limits<decltype(size_)>::max(); }
|
||||
|
||||
inline constexpr bool empty() const noexcept { return size_ == 0; }
|
||||
|
||||
inline constexpr const char* begin() const noexcept { return str_; }
|
||||
|
@ -116,7 +118,7 @@ class cstring final {
|
|||
}
|
||||
|
||||
inline friend constexpr bool operator==(const cstring& lhs, const cstring& rhs) noexcept {
|
||||
return (lhs.size_ == rhs.size_) && equals(lhs.begin(), rhs.begin(), lhs.size());
|
||||
return (lhs.size_ == rhs.size_) && StrEquals(lhs.begin(), rhs.begin(), lhs.size());
|
||||
}
|
||||
|
||||
inline friend constexpr bool operator!=(const cstring& lhs, const cstring& rhs) noexcept {
|
||||
|
@ -125,12 +127,12 @@ class cstring final {
|
|||
|
||||
template <std::size_t N>
|
||||
inline friend constexpr bool operator==(const cstring& lhs, const char(&str)[N]) noexcept {
|
||||
return lhs == cstring{str, N - 1};
|
||||
return (lhs.size_ == N - 1) && StrEquals(lhs.begin(), str, lhs.size());
|
||||
}
|
||||
|
||||
template <std::size_t N>
|
||||
inline friend constexpr bool operator!=(const cstring& lhs, const char(&str)[N]) noexcept {
|
||||
return lhs != cstring{str, N - 1};
|
||||
return !(lhs == str);
|
||||
}
|
||||
|
||||
inline friend std::ostream& operator<<(std::ostream& os, const cstring& str) {
|
||||
|
@ -139,11 +141,6 @@ class cstring final {
|
|||
}
|
||||
|
||||
inline operator std::string() const { return std::string(begin(), size()); }
|
||||
|
||||
private:
|
||||
static inline constexpr bool equals(const char* lhs, const char* rhs, std::size_t size) {
|
||||
return size == 0 ? (lhs[0] == rhs[0]) : ((lhs[size - 1] == rhs[size - 1]) && equals(lhs, rhs, size - 1));
|
||||
}
|
||||
};
|
||||
|
||||
inline constexpr bool IsLexeme(char s) noexcept {
|
||||
|
|
Loading…
Reference in a new issue