From 4e764d2205387f74a5aebe89f070723fc955771d Mon Sep 17 00:00:00 2001 From: rexy712 Date: Wed, 29 Jun 2022 17:59:49 -0700 Subject: [PATCH] General header #include cleanup --- include/rexy/mpmc_queue.tpp | 6 +++--- include/rexy/string_base.hpp | 1 - include/rexy/string_view.tpp | 4 ++-- include/rexy/utility.hpp | 18 ++++++++---------- tests/basic_string.cpp | 6 +++--- 5 files changed, 16 insertions(+), 19 deletions(-) diff --git a/include/rexy/mpmc_queue.tpp b/include/rexy/mpmc_queue.tpp index 7c183d5..588ecb7 100644 --- a/include/rexy/mpmc_queue.tpp +++ b/include/rexy/mpmc_queue.tpp @@ -21,20 +21,20 @@ #include //forward, move #include //memory_order, atomic -#include //memcpy +#include "utility.hpp" //memcpy namespace rexy{ template mpmc_queue::slot::slot(const slot& s): m_turn(s.m_turn.load(std::memory_order_acquire)) { - memcpy(m_data, s.m_data, sizeof(s.m_data)); + rexy::memcpy(m_data, s.m_data, sizeof(s.m_data)); } template mpmc_queue::slot::slot(slot&& s): m_turn(s.m_turn.load(std::memory_order_acquire)) { - memcpy(m_data, s.m_data, sizeof(s.m_data)); + rexy::memcpy(m_data, s.m_data, sizeof(s.m_data)); } template mpmc_queue::slot::~slot(){ diff --git a/include/rexy/string_base.hpp b/include/rexy/string_base.hpp index 5707525..6a3fc9a 100644 --- a/include/rexy/string_base.hpp +++ b/include/rexy/string_base.hpp @@ -22,7 +22,6 @@ #include //is_same, integral_contant, enable_if, etc #include //forward #include //std::size_t,ptrdiff -#include //strlen #include //CHAR_BIT #include //reverse_iterator #include //ostream diff --git a/include/rexy/string_view.tpp b/include/rexy/string_view.tpp index 2acff8e..75226d6 100644 --- a/include/rexy/string_view.tpp +++ b/include/rexy/string_view.tpp @@ -41,11 +41,11 @@ namespace rexy{ template constexpr basic_string_view::basic_string_view(const_pointer c)noexcept: - basic_string_view(c, strlen(c)){} + basic_string_view(c, rexy::strlen(c)){} template constexpr basic_string_view& basic_string_view::operator=(const_pointer c)noexcept{ m_data = c; - m_length = strlen(c); + m_length = rexy::strlen(c); return *this; } diff --git a/include/rexy/utility.hpp b/include/rexy/utility.hpp index 8a42d2b..571d41e 100644 --- a/include/rexy/utility.hpp +++ b/include/rexy/utility.hpp @@ -21,14 +21,17 @@ #include //forward, move #include //size_t -#include -#include //strlen, strcmp, memcpy -#include //wcslen +#include //too many to enumerate #include //char_traits #include "compat/if_consteval.hpp" #include "rexy.hpp" +#ifdef REXY_if_consteval + #include //strlen, strcmp, memcpy + #include //wcslen +#endif + namespace rexy{ namespace{ @@ -92,11 +95,12 @@ namespace rexy{ return val > 0 ? val : -val; } -#ifdef REXY_if_consteval template constexpr std::size_t strlen(const T* c)noexcept{ return std::char_traits::length(c); } + +#ifdef REXY_if_consteval template constexpr int strcmp(const T* l, const T* r)noexcept{ REXY_if_not_consteval{ @@ -151,12 +155,6 @@ namespace rexy{ } } #else // REXY_if_consteval - template - constexpr std::size_t strlen(const T* c)noexcept{ - std::size_t i = 0; - for(;c[i];++i); - return i; - } template constexpr int strcmp(const T* l, const T* r)noexcept{ for(;*l == *r && *l;++l, ++r); diff --git a/tests/basic_string.cpp b/tests/basic_string.cpp index 12e25e8..79c0b35 100644 --- a/tests/basic_string.cpp +++ b/tests/basic_string.cpp @@ -1,9 +1,9 @@ #include "rexy/string.hpp" #include "rexy/allocator.hpp" +#include "rexy/utility.hpp" #include #include -#include #include #include @@ -90,7 +90,7 @@ void check_short_construction(){ } void check_long_construction(){ const char* data = "this is a really long string that should ensure that it makes a dynamic allocation even if it has a big buffer."; - std::size_t len = strlen(data); + std::size_t len = rexy::strlen(data); test_str str1(data); if(str1.length() != len) error("long constructed string should be length() == strlen(data)\n"); @@ -171,7 +171,7 @@ void check_long_assignment(){ const char* startdata1 = "this is another really long string that should ensure that it makes some sort of dyn alloc for big buf"; const char* startdata2 = "zy"; const char* data = "this is a really long string that should ensure that it makes a dynamic allocation even if it has a big buffer."; - std::size_t len = strlen(data); + std::size_t len = rexy::strlen(data); test_str str1(startdata1); str1 = data; if(str1.length() != len)