diff --git a/CMakeLists.txt b/CMakeLists.txt
index c25a988..5491d15 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -2,9 +2,9 @@ project(librexy)
cmake_minimum_required(VERSION 3.0.2)
include(GNUInstallDirs)
-set(librexy_VERSION_STRING "000010000L")
+set(librexy_VERSION_STRING "000020000L")
set(librexy_VERSION_MAJOR 0)
-set(librexy_VERSION_MINOR 1)
+set(librexy_VERSION_MINOR 2)
set(librexy_VERSION_REVISION 0)
set(INCLUDE_PATH ${CMAKE_SOURCE_DIR}/include)
include_directories(BEFORE SYSTEM "${INCLUDE_PATH}")
@@ -15,7 +15,7 @@ option(ENABLE_PROFILING "Enable asan" OFF)
option(BUILD_TESTS "Enable testing" OFF)
mark_as_advanced(ENABLE_PROFILING)
-set(SOURCE_LIST "src/filerd.cpp" "src/string.cpp" "src/binary.cpp" "src/static_string.cpp" "src/threadpool.cpp" "src/demangle.cpp")
+set(SOURCE_LIST "src/filerd.cpp" "src/string.cpp" "src/string_view.cpp" "src/threadpool.cpp" "src/demangle.cpp")
add_library(ensure OBJECT "src/ensure.cpp")
target_compile_options(ensure PRIVATE -Wall -Wextra -pedantic -std=c++20)
if(ENABLE_SHARED)
@@ -39,7 +39,7 @@ if(BUILD_TESTS)
add_subdirectory(tests)
endif()
-set(LIBREXY_PUBLIC_HEADERS "include/rexy/rexy.hpp" "include/rexy/algorithm.hpp" "include/rexy/utility.hpp" "include/rexy/basic_string_hash.hpp" "include/rexy/hash.hpp" "include/rexy/static_string_hash.hpp" "include/rexy/string_hash.hpp" "include/rexy/mpmc_queue.hpp" "include/rexy/mpmc_queue.tpp" "include/rexy/traits.hpp" "include/rexy/steal.hpp" "include/rexy/binary.hpp" "include/rexy/expression.hpp" "include/rexy/binary_base.hpp" "include/rexy/binary_base.tpp" "include/rexy/string_base.hpp" "include/rexy/string.hpp" "include/rexy/filerd.hpp" "include/rexy/string_base.tpp" "include/rexy/allocator.hpp" "include/rexy/meta.hpp" "include/rexy/buffer.hpp" "include/rexy/buffer.tpp" "include/rexy/debug_print.hpp" "include/rexy/deferred.hpp" "include/rexy/demangle.hpp" "include/rexy/enum_traits.hpp" "include/rexy/storage_for.hpp" "include/rexy/storage_for.tpp" "include/rexy/visitor.hpp")
+set(LIBREXY_PUBLIC_HEADERS "include/rexy/rexy.hpp" "include/rexy/algorithm.hpp" "include/rexy/utility.hpp" "include/rexy/basic_string_hash.hpp" "include/rexy/hash.hpp" "include/rexy/string_view_hash.hpp" "include/rexy/string_hash.hpp" "include/rexy/mpmc_queue.hpp" "include/rexy/mpmc_queue.tpp" "include/rexy/traits.hpp" "include/rexy/steal.hpp" "include/rexy/expression.hpp" "include/rexy/string_base.hpp" "include/rexy/string.hpp" "include/rexy/filerd.hpp" "include/rexy/string_base.tpp" "include/rexy/allocator.hpp" "include/rexy/meta.hpp" "include/rexy/buffer.hpp" "include/rexy/buffer.tpp" "include/rexy/debug_print.hpp" "include/rexy/deferred.hpp" "include/rexy/demangle.hpp" "include/rexy/enum_traits.hpp" "include/rexy/storage_for.hpp" "include/rexy/storage_for.tpp" "include/rexy/visitor.hpp" "include/rexy/string_view.hpp" "include/rexy/string_view.tpp")
target_compile_options(rexy PRIVATE -Wall -Wextra -pedantic -std=c++20)
install(TARGETS rexy
diff --git a/include/rexy/binary_base.hpp b/include/rexy/binary_base.hpp
deleted file mode 100644
index 5ab647e..0000000
--- a/include/rexy/binary_base.hpp
+++ /dev/null
@@ -1,257 +0,0 @@
-/**
- This file is a part of rexy's general purpose library
- Copyright (C) 2020 rexy712
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see .
-*/
-
-#ifndef REXY_BINARY_BASE_HPP
-#define REXY_BINARY_BASE_HPP
-
-#include //size_t
-#include //move
-#include //memcpy
-#include //ptrdiff_t
-#include
-#include //reverse_iterator
-
-#include "utility.hpp" //max
-#include "steal.hpp"
-#include "expression.hpp"
-#include "traits.hpp"
-#include "detail/string_appender.hpp"
-#include "detail/hasallocator.hpp"
-#include "rexy.hpp"
-
-namespace rexy{
-
- class binary_base
- {
- public:
- using value_type = char;
- using size_type = size_t;
- using difference_type = ptrdiff_t;
- using pointer = value_type*;
- using const_pointer = const value_type*;
- using reference = value_type&;
- using const_reference = const value_type&;
- using iterator = pointer;
- using const_iterator = const_pointer;
- using reverse_iterator = std::reverse_iterator;
- using const_reverse_iterator = std::reverse_iterator;
-
- protected:
- pointer m_data = nullptr;
- size_type m_size = 0;
- size_type m_cap = 0;
- protected:
- constexpr binary_base(void)noexcept = default;
- constexpr binary_base(size_type len)noexcept;
- constexpr binary_base(pointer data, size_type size)noexcept;
- constexpr binary_base(pointer data, size_type size, size_type cap)noexcept;
- constexpr binary_base(const binary_base& b)noexcept;
- ~binary_base(void)noexcept = default;
-
- public:
- constexpr pointer release(void)noexcept;
-
- constexpr size_type size(void)const;
- constexpr size_type capacity(void)const;
- constexpr pointer get(void);
- constexpr const_pointer get(void)const;
- constexpr operator bool(void)const;
-
- constexpr reference operator[](size_type i)noexcept;
- constexpr const_reference operator[](size_type i)const noexcept;
-
- constexpr iterator begin(void);
- constexpr const_iterator begin(void)const;
- constexpr iterator end(void);
- constexpr const_iterator end(void)const;
- constexpr const_iterator cbegin(void)const;
- constexpr const_iterator cend(void)const;
-
- constexpr reverse_iterator rbegin(void);
- constexpr const_reverse_iterator rbegin(void)const;
- constexpr reverse_iterator rend(void);
- constexpr const_reverse_iterator rend(void)const;
- constexpr const_reverse_iterator crbegin(void)const;
- constexpr const_reverse_iterator crend(void)const;
- };
- template
- class basic_binary : protected detail::hasallocator, public binary_base
- {
- public:
- using allocator_type = Allocator;
-
- public:
- constexpr basic_binary(void)noexcept;
- constexpr basic_binary(rexy::steal data, size_type size)noexcept;
- constexpr basic_binary(rexy::steal data, size_type cap, size_type size)noexcept;
- constexpr basic_binary(rexy::steal data)noexcept;
- basic_binary(const_pointer data, size_type size)noexcept(noexcept(this->allocate(0)));
- basic_binary(const_pointer data)noexcept(noexcept(this->allocate(0)));
- basic_binary(const_pointer data, size_type size, size_type cap)noexcept(noexcept(this->allocate(0)));
- explicit basic_binary(size_type size)noexcept(noexcept(this->allocate(0)));
- basic_binary(size_type size, size_type cap)noexcept(noexcept(this->allocate(0)));
-
- basic_binary(const basic_binary& b)noexcept(noexcept(this->allocate(0)));
- constexpr basic_binary(basic_binary&& b)noexcept;
- basic_binary(const binary_base& b)noexcept(noexcept(this->allocate(0)));
-
- ~basic_binary(void)noexcept(noexcept(this->deallocate(nullptr,0)));
-
- basic_binary& operator=(const basic_binary& b)noexcept(noexcept(this->allocate(0)));
- constexpr basic_binary& operator=(basic_binary&& b)noexcept;
- basic_binary& operator=(const_pointer c)noexcept(noexcept(this->allocate(0)));
- basic_binary& operator=(const binary_base& b)noexcept(noexcept(this->allocate(0)));
-
- void reset(void)
- noexcept(noexcept(this->deallocate(nullptr,0)));
- void reset(pointer val, size_type cap, size_type size = 0)
- noexcept(noexcept(this->deallocate(nullptr,0)));
- bool resize(size_type newsize)
- noexcept(noexcept(this->allocate(0)) &&
- noexcept(this->deallocate(nullptr,0)));
- void append(const_pointer data, size_type len)
- noexcept(noexcept(this->allocate(0)) &&
- noexcept(this->deallocate(nullptr,0)));
-
- using detail::hasallocator::allocator;
-
- private:
- basic_binary& _copy_data(const_pointer data, size_type len)
- noexcept(noexcept(this->allocate(0)) &&
- noexcept(this->deallocate(nullptr,0)));
- };
-
- template
- class binary_cat_expr : public rexy::binary_expression
- {
- private:
- using left_t = std::decay_t;
- using right_t = std::decay_t;
- static_assert(std::is_same::value);
- public:
- using value_type = typename left_t::value_type;
- using size_type = decltype(typename left_t::size_type{0} + typename right_t::size_type{0});
- using difference_type = decltype(typename left_t::difference_type{0} - typename right_t::difference_type{0});
- using pointer = value_type*;
- using const_pointer = const value_type*;
- using reference = value_type&;
- using const_reference = const value_type&;
- using iterator = pointer;
- using const_iterator = const_pointer;
-
- public:
- using binary_expression::binary_expression;
-
- constexpr binary_cat_expr(const binary_cat_expr&) = default;
- constexpr binary_cat_expr(binary_cat_expr&&) = default;
-
- constexpr size_type size(void)const noexcept;
-
- template
- operator basic_binary(void)
- noexcept(std::is_nothrow_constructible, typename basic_binary::size_type>::value &&
- std::is_nothrow_invocable>,decltype(*this)>::value);
- };
-
- class static_binary : public binary_base
- {
- public:
- constexpr static_binary(void)noexcept = default;
- constexpr static_binary(const_pointer str, size_type len)noexcept;
- constexpr static_binary(const_pointer str)noexcept;
- constexpr static_binary(const static_binary&)noexcept;
- constexpr static_binary(static_binary&&)noexcept;
- ~static_binary(void)noexcept = default;
-
- constexpr static_binary& operator=(const_pointer str)noexcept;
- constexpr static_binary& operator=(const static_binary& str)noexcept;
- constexpr static_binary& operator=(static_binary&& str)noexcept;
- };
-
- template
- binary_cat_expr(Left&&, Right&&) -> binary_cat_expr;
-
- template
- struct is_binary{
- static constexpr bool value = rexy::is_type::value || rexy::is_template_type::value;
- };
- template
- struct is_concrete_binary{
- static constexpr bool value = rexy::is_type::value;
- };
- namespace detail{
- template
- using enable_if_binary = std::enable_if_t<(is_binary::value && ...),int>;
- template
- using enable_if_concrete_binary = std::enable_if_t<(is_concrete_binary::value && ...),int>;
-
- }
-
- template = 0>
- bool operator==(Left&& l, Right&& r)noexcept{
- return l && r && l.size() == r.size() && l.capacity() == r.capacity() && !memcmp(l.get(), r.get(), l.size());
- }
- template = 0>
- bool operator!=(Left&& l, Right&& r)noexcept{
- return !(std::forward(l) == std::forward(r));
- }
- template = 0>
- auto operator+(Left&& l, Right&& r)
- noexcept(noexcept(::new (nullptr) binary_cat_expr(std::forward(l), std::forward(r))))
- {
- return binary_cat_expr(std::forward(l), std::forward(r));
- }
- template = 0>
- auto operator+(Left&& l, const char* c)
- noexcept(noexcept(::new (nullptr) binary_cat_expr(std::forward(l), rexy::static_binary(c))))
- {
- return binary_cat_expr(std::forward(l), rexy::static_binary(c));
- }
- template = 0>
- auto operator+(const char* c, Right&& r)
- noexcept(noexcept(::new (nullptr) binary_cat_expr(rexy::static_binary(c), std::forward(r))))
- {
- return binary_cat_expr(rexy::static_binary(c), std::forward(r));
- }
- template = 0, detail::enable_if_binary = 0>
- decltype(auto) operator+=(Left& l, Right&& r)
- noexcept(noexcept(l + std::forward(r)) && std::is_nothrow_assignable(r))>::value)
- {
- return l = (l + std::forward(r));
- }
- template = 0>
- decltype(auto) operator+=(Left& l, const char* c)
- noexcept(noexcept(l + c) && std::is_nothrow_assignable::value)
- {
- return l = (l + c);
- }
-} //namespace rexy
-
-#include "binary_base.tpp"
-
-namespace{
- constexpr inline rexy::static_binary operator"" _sb(const char* str, size_t len)noexcept{
- return rexy::static_binary(str, len);
- }
-}
-
-#ifdef REXY_STRING_HPP
-#include "detail/binary_string_conv.hpp"
-#endif
-
-#endif
diff --git a/include/rexy/binary_base.tpp b/include/rexy/binary_base.tpp
deleted file mode 100644
index 2b3d18c..0000000
--- a/include/rexy/binary_base.tpp
+++ /dev/null
@@ -1,313 +0,0 @@
-/**
- This file is a part of rexy's general purpose library
- Copyright (C) 2020 rexy712
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see .
-*/
-
-#ifndef REXY_BINARY_BASE_TPP
-#define REXY_BINARY_BASE_TPP
-
-#include //size_t
-#include //move
-#include //memcpy
-#include
-#include "utility.hpp" //max
-#include "steal.hpp"
-#include "detail/string_appender.hpp"
-
-#define STOP_STRICT_ALIAS_WARNING(x) (x)
-
-namespace rexy{
-
- constexpr binary_base::binary_base(size_type len)noexcept:
- m_cap(len){}
- constexpr binary_base::binary_base(pointer data, size_type size)noexcept:
- m_data(data), m_cap(size){}
- constexpr binary_base::binary_base(pointer data, size_type size, size_type cap)noexcept:
- m_data(data), m_size(size), m_cap(cap){}
- constexpr binary_base::binary_base(const binary_base&)noexcept{}
-
- constexpr auto binary_base::release(void)noexcept -> pointer{
- return exchange(m_data, nullptr);
- }
-
- constexpr auto binary_base::size(void)const -> size_type{
- return m_size;
- }
- constexpr auto binary_base::capacity(void)const -> size_type{
- return m_cap;
- }
- constexpr auto binary_base::get(void) -> pointer{
- return m_data;
- }
- constexpr auto binary_base::get(void)const -> const_pointer{
- return m_data;
- }
- constexpr binary_base::operator bool(void)const{
- return m_data;
- }
-
- constexpr auto binary_base::operator[](size_type i)noexcept -> reference{
- return m_data[i];
- }
- constexpr auto binary_base::operator[](size_type i)const noexcept -> const_reference{
- return m_data[i];
- }
-
- constexpr auto binary_base::begin(void) -> iterator{
- return m_data;
- }
- constexpr auto binary_base::begin(void)const -> const_iterator{
- return m_data;
- }
- constexpr auto binary_base::end(void) -> iterator{
- return m_data + m_size;
- }
- constexpr auto binary_base::end(void)const -> const_iterator{
- return m_data + m_size;
- }
- constexpr auto binary_base::cbegin(void)const -> const_iterator{
- return m_data;
- }
- constexpr auto binary_base::cend(void)const -> const_iterator{
- return m_data + m_size;
- }
- constexpr auto binary_base::rbegin(void) -> reverse_iterator{
- return reverse_iterator(m_data + m_size);
- }
- constexpr auto binary_base::rbegin(void)const -> const_reverse_iterator{
- return reverse_iterator(m_data + m_size);
- }
- constexpr auto binary_base::rend(void) -> reverse_iterator{
- return reverse_iterator(m_data - 1);
- }
- constexpr auto binary_base::rend(void)const -> const_reverse_iterator{
- return reverse_iterator(m_data - 1);
- }
- constexpr auto binary_base::crbegin(void)const -> const_reverse_iterator{
- return rbegin();
- }
- constexpr auto binary_base::crend(void)const -> const_reverse_iterator{
- return rend();
- }
-
- template
- constexpr basic_binary::basic_binary(void)noexcept{}
- template
- constexpr basic_binary::basic_binary(rexy::steal data)noexcept:
- binary_base(data.value() ? strlen(data.value()) : 0)
- {
- m_data = data.value();
- m_size = m_cap;
- }
- template
- constexpr basic_binary::basic_binary(rexy::steal data, size_type size)noexcept:
- binary_base(data.value(), size){}
- template
- constexpr basic_binary::basic_binary(rexy::steal data, size_type cap, size_type size)noexcept:
- binary_base(data.value(), cap, size){}
-
- template
- basic_binary::basic_binary(const_pointer data, size_type size)
- noexcept(noexcept(this->allocate(0))):
- binary_base(size ? this->allocate(size) : nullptr, size)
- {
- if(size)
- memcpy(m_data, data, size);
- }
- template
- basic_binary::basic_binary(const_pointer data)
- noexcept(noexcept(this->allocate(0))):
- basic_binary(data ? this->allocate(strlen(data)) : nullptr, strlen(data))
- {
- if(data)
- memcpy(m_data, data, m_cap);
- }
- template
- basic_binary::basic_binary(const_pointer data, size_type size, size_type cap)
- noexcept(noexcept(this->allocate(0))):
- binary_base(size ? this->allocate(size) : nullptr, size, cap)
- {
- if(size)
- memcpy(m_data, data, size);
- }
- template
- basic_binary::basic_binary(size_type size)
- noexcept(noexcept(this->allocate(0))):
- binary_base(this->allocate(size), size){}
- template
- basic_binary::basic_binary(size_type size, size_type cap)
- noexcept(noexcept(this->allocate(0))):
- binary_base(size ? this->allocate(size) : nullptr, size, cap){}
- template
- basic_binary::basic_binary(const basic_binary& b)
- noexcept(noexcept(this->allocate(0))):
- binary_base(b.m_size ? this->allocate(b.m_size) : nullptr, b.m_size, b.m_size)
- {
- if(b.m_size)
- memcpy(m_data, b.m_data, b.m_size);
- }
- template
- constexpr basic_binary::basic_binary(basic_binary&& b)noexcept:
- binary_base(exchange(b.m_data, nullptr), b.m_size, b.m_cap){}
- template
- basic_binary::basic_binary(const binary_base& b)
- noexcept(noexcept(this->allocate(0))):
- binary_base(b.size() ? this->allocate(b.size()) : nullptr, b.size(), b.size())
- {
- if(b.size())
- memcpy(m_data, b.get(), b.size());
- }
- template
- basic_binary::~basic_binary(void)
- noexcept(noexcept(this->deallocate(nullptr,0)))
- {
- this->deallocate(m_data, m_cap);
- }
- template
- basic_binary& basic_binary::operator=(const basic_binary& b)
- noexcept(noexcept(this->allocate(0)))
- {
- return _copy_data(b.get(), b.size());
- }
- template
- constexpr basic_binary& basic_binary::operator=(basic_binary&& b)noexcept{
- m_size = b.m_size;
- m_cap = b.m_cap;
- swap(m_data, b.m_data);
- return *this;
- }
- template
- basic_binary& basic_binary::operator=(const_pointer c)
- noexcept(noexcept(this->allocate(0)))
- {
- return _copy_data(c, strlen(c));
- }
- template
- basic_binary& basic_binary::operator=(const binary_base& b)
- noexcept(noexcept(this->allocate(0)))
- {
- return _copy_data(b.get(), b.size());
- }
- template
- void basic_binary::reset(void)
- noexcept(noexcept(this->deallocate(nullptr,0)))
- {
- this->deallocate(m_data, m_cap);
- m_data = nullptr;
- m_cap = m_size = 0;
- }
- template
- void basic_binary::reset(pointer val, size_type cap, size_type size)
- noexcept(noexcept(this->deallocate(nullptr,0)))
- {
- this->deallocate(m_data, m_cap);
- m_data = val;
- m_cap = cap;
- m_size = size;
- }
- template
- bool basic_binary::resize(size_type newsize)
- noexcept(noexcept(this->allocate(0)) &&
- noexcept(this->deallocate(nullptr,0)))
- {
- if(newsize < m_cap)
- return false;
- basic_binary tmp(newsize);
- if(!tmp)
- return false;
- memcpy(STOP_STRICT_ALIAS_WARNING(tmp).m_data, m_data, m_size);
- swap(m_data, STOP_STRICT_ALIAS_WARNING(tmp).m_data);
- m_cap = STOP_STRICT_ALIAS_WARNING(tmp).m_cap;
- return true;
- }
- template
- void basic_binary::append(const_pointer data, size_type len)
- noexcept(noexcept(this->allocate(0)) &&
- noexcept(this->deallocate(nullptr,0)))
- {
- if(m_size + len > m_cap)
- resize(max(m_cap*2, m_size+len));
- memcpy(m_data+m_size, data, len);
- m_size += len;
- }
- template
- basic_binary& basic_binary::_copy_data(const_pointer data, size_type len)
- noexcept(noexcept(this->allocate(0)) &&
- noexcept(this->deallocate(nullptr,0)))
- {
- if(!len)
- return (*this = basic_binary(rexy::steal(nullptr), 0, 0));
- if(len <= m_size){
- m_size = len;
- memcpy(m_data, data, len);
- return *this;
- }
- return (*this = basic_binary(data, len));
- }
-
- constexpr static_binary::static_binary(const_pointer str, size_type len)noexcept:
- binary_base(const_cast(str), len, len){}
- constexpr static_binary::static_binary(const_pointer str)noexcept:
- static_binary(str, strlen(str)){}
- constexpr static_binary::static_binary(const static_binary& s)noexcept:
- static_binary(s.get(), s.size()){}
- constexpr static_binary::static_binary(static_binary&& s)noexcept:
- static_binary(s.get(), s.size()){}
-
- constexpr static_binary& static_binary::operator=(const_pointer str)noexcept{
- m_data = const_cast(str);
- m_size = strlen(str);
- m_cap = m_size;
- return *this;
- }
- constexpr static_binary& static_binary::operator=(const static_binary& str)noexcept{
- m_data = str.m_data;
- m_size = str.m_size;
- m_cap = str.m_cap;
- return *this;
- }
- constexpr static_binary& static_binary::operator=(static_binary&& str)noexcept{
- m_data = str.m_data;
- m_size = str.m_size;
- m_cap = str.m_cap;
- return *this;
- }
-
- template
- constexpr auto binary_cat_expr::size(void)const noexcept -> size_type{
- return this->m_l.size() + this->m_r.size();
- }
-
- template
- template
- binary_cat_expr::operator basic_binary(void)
- noexcept(std::is_nothrow_constructible, typename basic_binary::size_type>::value &&
- std::is_nothrow_invocable>,decltype(*this)>::value)
- {
- auto sz = size();
- basic_binary ret(sz);
-
- detail::string_appender> append(ret);
-
- append(*this);
- return ret;
- }
-
-}
-
-#undef STOP_STRICT_ALIAS_WARNING
-
-#endif
diff --git a/include/rexy/buffer.hpp b/include/rexy/buffer.hpp
index a4d026e..89ffea9 100644
--- a/include/rexy/buffer.hpp
+++ b/include/rexy/buffer.hpp
@@ -24,6 +24,8 @@
#include //size_t, ptrdiff_t
#include //reverse_iterator
+#include "compat/constexpr.hpp"
+
namespace rexy{
template>
@@ -50,22 +52,22 @@ namespace rexy{
public:
constexpr buffer(void);
- buffer(const_pointer data, size_type length)noexcept(noexcept(this->allocate(0)));
+ REXY_CPP20_CONSTEXPR buffer(const_pointer data, size_type length)noexcept(noexcept(this->allocate(0)));
template
- buffer(const Iter& start, const Iter& last);
- buffer(size_type cap)noexcept(noexcept(this->allocate(0)));
- buffer(const buffer& b)noexcept(noexcept(this->allocate(0)));
+ REXY_CPP20_CONSTEXPR buffer(const Iter& start, const Iter& last);
+ REXY_CPP20_CONSTEXPR buffer(size_type cap)noexcept(noexcept(this->allocate(0)));
+ REXY_CPP20_CONSTEXPR buffer(const buffer& b)noexcept(noexcept(this->allocate(0)));
constexpr buffer(buffer&& b)noexcept;
- ~buffer(void)noexcept(noexcept(this->deallocate(nullptr, 0)));
+ REXY_CPP20_CONSTEXPR ~buffer(void)noexcept(noexcept(this->deallocate(nullptr, 0)));
- buffer& operator=(const buffer& b)
+ REXY_CPP20_CONSTEXPR buffer& operator=(const buffer& b)
noexcept(noexcept(this->allocate(0)) &&
noexcept(this->deallocate(nullptr, 0)));
constexpr buffer& operator=(buffer&& b)noexcept;
constexpr pointer data(void);
constexpr const_pointer data(void)const;
- void resize(size_type new_cap);
+ REXY_CPP20_CONSTEXPR void resize(size_type new_cap);
constexpr void set_size(size_type size);
constexpr size_type cap(void)const;
constexpr const size_type& size(void)const;
@@ -91,6 +93,7 @@ namespace rexy{
constexpr const_reverse_iterator crbegin(void)const;
constexpr const_reverse_iterator crend(void)const;
+ REXY_CPP20_CONSTEXPR void append(const_pointer p, size_type len);
};
}
diff --git a/include/rexy/buffer.tpp b/include/rexy/buffer.tpp
index c87358e..ae0e96e 100644
--- a/include/rexy/buffer.tpp
+++ b/include/rexy/buffer.tpp
@@ -20,13 +20,14 @@
#define REXY_BUFFER_TPP
#include //exchange, swap
+#include //max
namespace rexy{
template
constexpr buffer::buffer(void){}
template
- buffer::buffer(const_pointer data, size_type length)noexcept(noexcept(this->allocate(0))):
+ REXY_CPP20_CONSTEXPR buffer::buffer(const_pointer data, size_type length)noexcept(noexcept(this->allocate(0))):
m_data(this->allocate(sizeof(value_type) * length)),
m_cap(length),
m_size(length)
@@ -37,7 +38,7 @@ namespace rexy{
}
template
template
- buffer::buffer(const Iter& start, const Iter& last){
+ REXY_CPP20_CONSTEXPR buffer::buffer(const Iter& start, const Iter& last){
size_type count = 0;
for(auto it = start;it != end;++it){
++count;
@@ -53,12 +54,12 @@ namespace rexy{
m_size = count;
}
template
- buffer::buffer(size_type cap)noexcept(noexcept(this->allocate(0))):
+ REXY_CPP20_CONSTEXPR buffer::buffer(size_type cap)noexcept(noexcept(this->allocate(0))):
m_data(this->allocate(sizeof(value_type) * cap)),
m_cap(cap),
m_size(0){}
template
- buffer::buffer(const buffer& b)noexcept(noexcept(this->allocate(0))):
+ REXY_CPP20_CONSTEXPR buffer::buffer(const buffer& b)noexcept(noexcept(this->allocate(0))):
m_data(this->allocate(sizeof(value_type) * b.m_cap)),
m_cap(b.m_cap),
m_size(b.m_size)
@@ -73,14 +74,14 @@ namespace rexy{
m_cap(b.m_cap),
m_size(b.m_size){}
template
- buffer::~buffer(void)noexcept(noexcept(this->deallocate(nullptr, 0))){
+ REXY_CPP20_CONSTEXPR buffer::~buffer(void)noexcept(noexcept(this->deallocate(nullptr, 0))){
for(size_type i = 0;i < m_size;++i){
m_data[i].~T();
}
this->deallocate(m_data, m_cap * sizeof(value_type));
}
template
- buffer& buffer::operator=(const buffer& b)
+ REXY_CPP20_CONSTEXPR buffer& buffer::operator=(const buffer& b)
noexcept(noexcept(this->allocate(0)) &&
noexcept(this->deallocate(nullptr, 0)))
{
@@ -102,7 +103,7 @@ namespace rexy{
return m_data;
}
template
- void buffer::resize(size_type new_cap){
+ REXY_CPP20_CONSTEXPR void buffer::resize(size_type new_cap){
if(new_cap > m_cap){
buffer tmp(new_cap);
for(size_type i = 0;i < m_size;++i){
@@ -199,6 +200,16 @@ namespace rexy{
return const_reverse_iterator(m_data - 1);
}
+ template
+ REXY_CPP20_CONSTEXPR void buffer::append(const_pointer p, size_type len){
+ if(len + m_size > m_cap){
+ resize(std::max(m_cap * 2, len + m_size));
+ }
+ for(size_type i = 0;i < len;++i){
+ new (m_data + (m_size + i)) T(p[i]);
+ }
+ }
+
}
#endif
diff --git a/include/rexy/detail/cpp20.hpp b/include/rexy/compat/constexpr.hpp
similarity index 100%
rename from include/rexy/detail/cpp20.hpp
rename to include/rexy/compat/constexpr.hpp
diff --git a/include/rexy/compat/cpp17/source_location.hpp b/include/rexy/compat/cpp17/source_location.hpp
new file mode 100644
index 0000000..9965db8
--- /dev/null
+++ b/include/rexy/compat/cpp17/source_location.hpp
@@ -0,0 +1,107 @@
+/**
+ This file is a part of rexy's general purpose library
+ Copyright (C) 2022 rexy712
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+*/
+
+#ifndef REXY_COMPAT_17_SOURCE_LOCATION_HPP
+#define REXY_COMPAT_17_SOURCE_LOCATION_HPP
+
+#include //uint_least32_t
+
+//clang bug: https://bugs.llvm.org/show_bug.cgi?id=48886
+#if __cplusplus >= 202002L && !defined(__clang__)
+ #define CONSTEVAL consteval
+#else
+ #define CONSTEVAL constexpr
+#endif
+
+namespace rexy::compat::cpp17{
+
+ class source_location
+ {
+ private:
+ const char* m_file;
+ const char* m_func;
+ uint_least32_t m_line;
+ uint_least32_t m_column;
+
+ public:
+ constexpr source_location(void)noexcept;
+ constexpr source_location(const source_location&);
+ constexpr source_location(source_location&&)noexcept;
+
+ constexpr uint_least32_t line(void)const noexcept;
+ constexpr uint_least32_t column(void)const noexcept;
+ constexpr const char* file_name(void)const noexcept;
+ constexpr const char* function_name(void)const noexcept;
+
+ public:
+ #if (defined(__clang__) && (__clang_major__ >= 9)) || (defined(_MSC_VER) && (_MSC_VER >= 1926))
+ static CONSTEVAL source_location current(uint_least32_t line = __builtin_LINE(),
+ uint_least32_t col = __builtin_COLUMN(),
+ const char* file = __builtin_FILE(),
+ const char* func = __builtin_FUNCTION())noexcept;
+ #elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8))
+ static CONSTEVAL source_location current(uint_least32_t line = __builtin_LINE(),
+ uint_least32_t col = 0,
+ const char* file = __builtin_FILE(),
+ const char* func = __builtin_FUNCTION())noexcept;
+ #else
+ static CONSTEVAL source_location current(uint_least32_t line = 0,
+ uint_least32_t col = 0,
+ const char* file = "unknown",
+ const char* func = "unknown")noexcept;
+ #endif
+
+ private:
+ constexpr source_location(uint_least32_t line, uint_least32_t col, const char* file, const char* func)noexcept;
+ };
+
+ constexpr source_location::source_location(void)noexcept:
+ source_location(0, 0, "unknown", "unknown"){}
+ constexpr source_location::source_location(const source_location& s):
+ source_location(s.m_line, s.m_column, s.m_file, s.m_func){}
+ constexpr source_location::source_location(source_location&& s)noexcept:
+ source_location(s.m_line, s.m_column, s.m_file, s.m_func){}
+ constexpr source_location::source_location(uint_least32_t line, uint_least32_t col, const char* file, const char* func)noexcept:
+ m_file(file),
+ m_func(func),
+ m_line(line),
+ m_column(col){}
+
+ constexpr uint_least32_t source_location::line(void)const noexcept{
+ return m_line;
+ }
+ constexpr uint_least32_t source_location::column(void)const noexcept{
+ return m_column;
+ }
+ constexpr const char* source_location::file_name(void)const noexcept{
+ return m_file;
+ }
+ constexpr const char* source_location::function_name(void)const noexcept{
+ return m_func;
+ }
+
+ CONSTEVAL source_location source_location::current(uint_least32_t line, uint_least32_t col, const char* file, const char* func)noexcept{
+ return source_location(line, col, file, func);
+ }
+
+
+#undef CONSTEVAL
+
+}
+
+#endif
diff --git a/include/rexy/binary.hpp b/include/rexy/compat/cpp17/to_address.hpp
similarity index 68%
rename from include/rexy/binary.hpp
rename to include/rexy/compat/cpp17/to_address.hpp
index 91600b3..548826d 100644
--- a/include/rexy/binary.hpp
+++ b/include/rexy/compat/cpp17/to_address.hpp
@@ -1,6 +1,6 @@
/**
This file is a part of rexy's general purpose library
- Copyright (C) 2020 rexy712
+ Copyright (C) 2022 rexy712
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -16,18 +16,19 @@
along with this program. If not, see .
*/
-#ifndef REXY_BINARY_HPP
-#define REXY_BINARY_HPP
+#ifndef REXY_COMPAT_17_TO_ADDRESS_HPP
+#define REXY_COMPAT_17_TO_ADDRESS_HPP
-#include "binary_base.hpp"
-#include "allocator.hpp"
-#include "rexy.hpp"
+namespace rexy::compat::cpp17{
-namespace rexy{
-
- using binary = basic_binary>;
-
- extern template class basic_binary>;
+ template
+ constexpr T* to_address(T* p)noexcept{
+ return p;
+ }
+ template
+ constexpr auto to_address(const Ptr& p)noexcept{
+ return to_address(p.operator->());
+ }
}
diff --git a/src/binary.cpp b/include/rexy/compat/cpp20/source_location.hpp
similarity index 75%
rename from src/binary.cpp
rename to include/rexy/compat/cpp20/source_location.hpp
index 0659bd1..51a0297 100644
--- a/src/binary.cpp
+++ b/include/rexy/compat/cpp20/source_location.hpp
@@ -1,6 +1,6 @@
/**
This file is a part of rexy's general purpose library
- Copyright (C) 2020 rexy712
+ Copyright (C) 2022 rexy712
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -16,11 +16,15 @@
along with this program. If not, see .
*/
-#include "rexy/binary.hpp"
-#include "rexy/allocator.hpp"
+#ifndef REXY_COMPAT_20_SOURCE_LOCATION_HPP
+#define REXY_COMPAT_20_SOURCE_LOCATION_HPP
-namespace rexy{
+#include
- template class basic_binary>;
+namespace rexy::compat::cpp20{
+
+ using source_location = std::source_location;
}
+
+#endif
diff --git a/include/rexy/compat/cpp20/to_address.hpp b/include/rexy/compat/cpp20/to_address.hpp
new file mode 100644
index 0000000..d95823c
--- /dev/null
+++ b/include/rexy/compat/cpp20/to_address.hpp
@@ -0,0 +1,37 @@
+/**
+ This file is a part of rexy's general purpose library
+ Copyright (C) 2022 rexy712
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+*/
+
+#ifndef REXY_COMPAT_20_TO_ADDRESS_HPP
+#define REXY_COMPAT_20_TO_ADDRESS_HPP
+
+#include //to_address
+
+namespace rexy::compat::cpp20{
+
+ template
+ constexpr T* to_address(T* p)noexcept{
+ return std::to_address(p);
+ }
+ template
+ constexpr auto to_address(const Ptr& p)noexcept{
+ return std::to_address(p);
+ }
+
+}
+
+#endif
diff --git a/include/rexy/compat/source_location.hpp b/include/rexy/compat/source_location.hpp
index ec48ac5..d99cda3 100644
--- a/include/rexy/compat/source_location.hpp
+++ b/include/rexy/compat/source_location.hpp
@@ -23,101 +23,26 @@
#ifndef __cpp_lib_source_location
-#include //uint_least32_t
+ #include "cpp17/source_location.hpp"
-//clang bug: https://bugs.llvm.org/show_bug.cgi?id=48886
-#if __cplusplus >= 202002L && !defined(__clang__)
- #define CONSTEVAL consteval
-#else
- #define CONSTEVAL constexpr
-#endif
+ namespace rexy::compat{
-namespace rexy::compat{
+ using source_location = cpp17::source_location;
- class source_location
- {
- private:
- const char* m_file;
- const char* m_func;
- uint_least32_t m_line;
- uint_least32_t m_column;
-
- public:
- constexpr source_location(void)noexcept;
- constexpr source_location(const source_location&);
- constexpr source_location(source_location&&)noexcept;
-
- constexpr uint_least32_t line(void)const noexcept;
- constexpr uint_least32_t column(void)const noexcept;
- constexpr const char* file_name(void)const noexcept;
- constexpr const char* function_name(void)const noexcept;
-
- public:
- #if (defined(__clang__) && (__clang_major__ >= 9)) || (defined(_MSC_VER) && (_MSC_VER >= 1926))
- static CONSTEVAL source_location current(uint_least32_t line = __builtin_LINE(),
- uint_least32_t col = __builtin_COLUMN(),
- const char* file = __builtin_FILE(),
- const char* func = __builtin_FUNCTION())noexcept;
- #elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8))
- static CONSTEVAL source_location current(uint_least32_t line = __builtin_LINE(),
- uint_least32_t col = 0,
- const char* file = __builtin_FILE(),
- const char* func = __builtin_FUNCTION())noexcept;
- #else
- static CONSTEVAL source_location current(uint_least32_t line = 0,
- uint_least32_t col = 0,
- const char* file = "unknown",
- const char* func = "unknown")noexcept;
- #endif
-
- private:
- constexpr source_location(uint_least32_t line, uint_least32_t col, const char* file, const char* func)noexcept;
- };
-
- constexpr source_location::source_location(void)noexcept:
- source_location(0, 0, "unknown", "unknown"){}
- constexpr source_location::source_location(const source_location& s):
- source_location(s.m_line, s.m_column, s.m_file, s.m_func){}
- constexpr source_location::source_location(source_location&& s)noexcept:
- source_location(s.m_line, s.m_column, s.m_file, s.m_func){}
- constexpr source_location::source_location(uint_least32_t line, uint_least32_t col, const char* file, const char* func)noexcept:
- m_file(file),
- m_func(func),
- m_line(line),
- m_column(col){}
-
- constexpr uint_least32_t source_location::line(void)const noexcept{
- return m_line;
}
- constexpr uint_least32_t source_location::column(void)const noexcept{
- return m_column;
- }
- constexpr const char* source_location::file_name(void)const noexcept{
- return m_file;
- }
- constexpr const char* source_location::function_name(void)const noexcept{
- return m_func;
- }
-
- CONSTEVAL source_location source_location::current(uint_least32_t line, uint_least32_t col, const char* file, const char* func)noexcept{
- return source_location(line, col, file, func);
- }
-
-}
-
-#undef CONSTEVAL
#else //__cpp_lib_source_location
-#include
+ #include "cpp20/source_location.hpp"
-namespace rexy::compat{
+ namespace rexy::compat{
- using source_location = std::source_location;
+ using source_location = cpp20::source_location;
-}
+ }
#endif //__cpp_lib_source_location
+
#endif
diff --git a/include/rexy/compat/to_address.hpp b/include/rexy/compat/to_address.hpp
index 19d3428..bbf8748 100644
--- a/include/rexy/compat/to_address.hpp
+++ b/include/rexy/compat/to_address.hpp
@@ -19,32 +19,25 @@
#ifndef REXY_COMPAT_TO_ADDRESS_HPP
#define REXY_COMPAT_TO_ADDRESS_HPP
-#if __cplusplus >= 202002L
- #include //to_address
-#endif
+#ifdef __cpp_lib_to_address
+ #include "cpp20/to_address.hpp"
+ namespace rexy::compat{
-namespace rexy::compat{
-#if __cplusplus >= 202002L
- template
- constexpr T* to_address(T* p)noexcept{
- return std::to_address(p);
- }
- template
- constexpr auto to_address(const Ptr& p)noexcept{
- return std::to_address(p);
- }
-#else
- template
- constexpr T* to_address(T* p)noexcept{
- return p;
- }
- template
- constexpr auto to_address(const Ptr& p)noexcept{
- return to_address(p.operator->());
- }
-#endif
+ using cpp20::to_address;
+
+ }
+
+#else //__cpp_lib_to_address
+
+ #include "cpp17/to_address.hpp"
+ namespace rexy::compat{
+
+ using cpp17::to_address;
+
+ }
+
+#endif //__cpp_lib_to_address
-}
#endif
diff --git a/include/rexy/cx/string.hpp b/include/rexy/cx/string.hpp
index f0156d1..9ad85de 100644
--- a/include/rexy/cx/string.hpp
+++ b/include/rexy/cx/string.hpp
@@ -29,7 +29,7 @@ namespace rexy::cx{
#include
#include //ptrdiff_t, size_t
-#include "../detail/cpp20.hpp"
+#include "../compat/constexpr.hpp"
//This is different from rexy::static_string in that this doesn't hold a pointer to a constant string array.
//This holds a mutable array of data which can be modified during compile time. static_string is
diff --git a/include/rexy/detail/binary_string_conv.hpp b/include/rexy/detail/binary_string_conv.hpp
deleted file mode 100644
index 3d966f1..0000000
--- a/include/rexy/detail/binary_string_conv.hpp
+++ /dev/null
@@ -1,55 +0,0 @@
-/**
- This file is a part of rexy's general purpose library
- Copyright (C) 2020 rexy712
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see .
-*/
-
-#ifndef REXY_BINARY_STRING_CONV_HPP
-#define REXY_BINARY_STRING_CONV_HPP
-
-#include "rexy/string_base.hpp"
-#include "rexy/binary_base.hpp"
-#include //memcpy
-
-namespace rexy{
- template,int> = 0>
- auto binary_to_string(const binary_base& b)
- noexcept(std::is_nothrow_constructible::value)
- {
- Str s(b.size()+1);
- s.append(b.get(), b.size());
- return s;
- }
- template,int> = 0, std::enable_if_t,typename Str::allocator_type>::value,int> = 0>
- auto binary_to_string(basic_binary&& b)noexcept{
- return Str(rexy::steal(b.release()), b.size());
- }
- template = 0>
- auto string_to_binary(const string_base& s)
- noexcept(std::is_nothrow_constructible::value &&
- noexcept(std::decay_t::allocator_type::allocate(0)))
- {
- Bin b(s.length()+1);
- b.append(s.get(), s.length()+1);
- return b;
- }
- template = 0, std::enable_if_t,typename Bin::allocator_type>::value,int> = 0>
- auto string_to_binary(basic_string&& s)noexcept{
- return Bin(rexy::steal(s.release()), s.length());
- }
-
-} //namespace rexy
-
-#endif
diff --git a/include/rexy/filerd.hpp b/include/rexy/filerd.hpp
index 4b3c423..e196da1 100644
--- a/include/rexy/filerd.hpp
+++ b/include/rexy/filerd.hpp
@@ -25,9 +25,9 @@
#include "string.hpp"
#include "steal.hpp"
-#include "binary.hpp"
#include "utility.hpp"
#include "rexy.hpp"
+#include "buffer.hpp"
namespace rexy{
@@ -65,7 +65,7 @@ namespace rexy{
size_t read(char* dest, size_t bytes)noexcept;
rexy::string read(size_t bytes)noexcept;
rexy::string readln(size_t max = 0)noexcept;
- rexy::binary read_bin(size_t bytes)noexcept(std::is_nothrow_constructible, size_t, size_t>::value);
+ rexy::buffer read_bin(size_t bytes)noexcept(std::is_nothrow_constructible, char*, size_t>::value);
size_t write(const char* c, size_t bytes)noexcept;
size_t write(const rexy::string_base& s)noexcept;
diff --git a/include/rexy/hash.hpp b/include/rexy/hash.hpp
index 7507939..2b99bd7 100644
--- a/include/rexy/hash.hpp
+++ b/include/rexy/hash.hpp
@@ -41,7 +41,7 @@ namespace rexy{
}
#ifdef REXY_STRING_BASE_HPP
-#include "static_string_hash.hpp"
+#include "string_view_hash.hpp"
#endif
#ifdef REXY_STRING_HPP
#include "basic_string_hash.hpp"
diff --git a/include/rexy/storage_for.hpp b/include/rexy/storage_for.hpp
index 3d308e4..2304917 100644
--- a/include/rexy/storage_for.hpp
+++ b/include/rexy/storage_for.hpp
@@ -70,7 +70,7 @@ namespace rexy{
constexpr reference operator*(void)noexcept;
constexpr const_reference operator*(void)const noexcept;
- bool valid(void)const;
+ constexpr bool valid(void)const;
};
}
diff --git a/include/rexy/storage_for.tpp b/include/rexy/storage_for.tpp
index 5e0e53b..544d15e 100644
--- a/include/rexy/storage_for.tpp
+++ b/include/rexy/storage_for.tpp
@@ -114,7 +114,7 @@ namespace rexy{
}
template
- bool storage_for::valid(void)const{
+ constexpr bool storage_for::valid(void)const{
return m_dirty;
}
diff --git a/include/rexy/string_base.hpp b/include/rexy/string_base.hpp
index dd11dc4..1478321 100644
--- a/include/rexy/string_base.hpp
+++ b/include/rexy/string_base.hpp
@@ -1,6 +1,6 @@
/**
This file is a part of rexy's general purpose library
- Copyright (C) 2020 rexy712
+ Copyright (C) 2020-2022 rexy712
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -35,7 +35,7 @@
#include "detail/hasallocator.hpp"
#include "rexy.hpp"
-#include "detail/cpp20.hpp"
+#include "compat/constexpr.hpp"
#if __cplusplus >= 202002L
#include
@@ -44,82 +44,7 @@
namespace rexy{
template
- class string_base;
-
- template
- class basic_string_view
- {
- public:
- using value_type = Char;
- using size_type = size_t;
- using difference_type = ptrdiff_t;
- using pointer = value_type*;
- using const_pointer = const value_type*;
- using reference = value_type&;
- using const_reference = const value_type&;
- using iterator = pointer;
- using const_iterator = const_pointer;
- using reverse_iterator = std::reverse_iterator;
- using const_reverse_iterator = std::reverse_iterator;
-
- private:
- const_pointer m_data = nullptr;
- size_type m_length = 0;
-
- public:
- constexpr basic_string_view(void)noexcept;
- constexpr basic_string_view(const_pointer str, size_type len)noexcept;
- constexpr basic_string_view(const_pointer c)noexcept;
- constexpr basic_string_view(const basic_string_view& s)noexcept;
- constexpr basic_string_view(const string_base& s)noexcept;
- constexpr basic_string_view(basic_string_view&& s)noexcept;
- template
- constexpr basic_string_view(InIter start, InIter fin)noexcept;
- REXY_CPP20_CONSTEXPR ~basic_string_view(void)noexcept = default;
-
- constexpr basic_string_view& operator=(const_pointer c)noexcept;
- constexpr basic_string_view& operator=(const basic_string_view& s)noexcept;
- constexpr basic_string_view& operator=(basic_string_view&&)noexcept;
-
-
- //Length of string not including null terminator
- constexpr size_type length(void)const noexcept{return m_length;}
- //direct access to managed pointer
- constexpr const_pointer c_str(void)const noexcept{return m_data;}
- constexpr const_pointer get(void)const noexcept{return m_data;}
- constexpr operator const_pointer(void)const noexcept{return m_data;}
- //true if m_data is not empty
- constexpr bool valid(void)const noexcept{return m_length > 0;}
-
- constexpr const_reference operator[](size_type i)const noexcept{return m_data[i];}
-
- constexpr const_iterator search(const basic_string_view& s)const;
- constexpr const_iterator search(const_pointer c)const;
- template
- constexpr const_iterator search(const basic_string_view& s, const Searcher& searcher)const;
- template
- constexpr const_iterator search(const_pointer c, const Searcher& searcher)const;
- constexpr bool compare(const basic_string_view& s)const{return *this == s;}
- constexpr bool compare(const_pointer c)const{return *this == c;}
-
- constexpr const_iterator begin(void)const{return m_data;}
- constexpr const_iterator end(void)const{return m_data+m_length;}
- constexpr const_iterator cbegin(void)const{return begin();}
- constexpr const_iterator cend(void)const{return end();}
-
- constexpr const_reverse_iterator rbegin(void)const{return const_reverse_iterator(m_data+m_length);}
- constexpr const_reverse_iterator rend(void)const{return const_reverse_iterator(m_data-1);}
- constexpr const_reverse_iterator crbegin(void)const{return rbegin();}
- constexpr const_reverse_iterator crend(void)const{return rend();}
- };
-
- template
- basic_string_view(const T*) -> basic_string_view;
- template
- basic_string_view(const T*, size_t) -> basic_string_view;
-
- template
- using static_string [[deprecated]] = basic_string_view;
+ class basic_string_view;
//Base of all RAII strings. Its use is allowing passing of rexy strings to functions without knowing the exact type
template
@@ -163,7 +88,7 @@ namespace rexy{
length(0),
data{}{}
};
- //union of short and long string representations. Default to long representation for string_view's use case.
+ //union of short and long string representations. Default to long representation for wstring_view's use case.
union combine_data{
ldata l;
sdata s;
@@ -633,9 +558,6 @@ namespace rexy{
template
static constexpr bool is_string_v = is_string::value;
- static_assert(is_string_v>);
-
-
template
struct are_strings{
static constexpr bool value = (is_string::value && ...);
@@ -777,44 +699,10 @@ namespace rexy{
#include "string_base.tpp"
namespace{
- [[deprecated]]
- constexpr inline rexy::basic_string_view operator"" _ss(const char* str, size_t len)noexcept{
- return rexy::basic_string_view(str, len);
- }
- [[deprecated]]
- constexpr inline rexy::basic_string_view operator"" _ss(const wchar_t* str, size_t len)noexcept{
- return rexy::basic_string_view(str, len);
- }
- [[deprecated]]
- constexpr inline rexy::basic_string_view operator"" _ss(const char16_t* str, size_t len)noexcept{
- return rexy::basic_string_view(str, len);
- }
- [[deprecated]]
- constexpr inline rexy::basic_string_view operator"" _ss(const char32_t* str, size_t len)noexcept{
- return rexy::basic_string_view(str, len);
- }
-
- constexpr inline rexy::basic_string_view operator"" _sv(const char* str, size_t len)noexcept{
- return rexy::basic_string_view(str, len);
- }
- constexpr inline rexy::basic_string_view operator"" _sv(const wchar_t* str, size_t len)noexcept{
- return rexy::basic_string_view(str, len);
- }
- constexpr inline rexy::basic_string_view operator"" _sv(const char16_t* str, size_t len)noexcept{
- return rexy::basic_string_view(str, len);
- }
- constexpr inline rexy::basic_string_view operator"" _sv(const char32_t* str, size_t len)noexcept{
- return rexy::basic_string_view(str, len);
- }
-
template
std::ostream& operator<<(std::ostream& os, const rexy::basic_string& str){
return os << str.c_str();
}
- template
- std::ostream& operator<<(std::ostream& os, const rexy::basic_string_view& str){
- return os << str.c_str();
- }
}
diff --git a/include/rexy/string_base.tpp b/include/rexy/string_base.tpp
index 3244873..0367c42 100644
--- a/include/rexy/string_base.tpp
+++ b/include/rexy/string_base.tpp
@@ -27,6 +27,7 @@
#include "detail/string_appender.hpp"
#include "algorithm.hpp"
#include "compat/to_address.hpp"
+#include "string_view.hpp"
#define STOP_STRICT_ALIAS_WARNING(x) (x)
@@ -382,49 +383,6 @@ namespace rexy{
}
- template
- constexpr basic_string_view::basic_string_view(void)noexcept:
- basic_string_view(nullptr, 0){}
-
- template
- constexpr basic_string_view::basic_string_view(const_pointer str, size_type len)noexcept:
- m_data(str), m_length(len){}
- template
- constexpr basic_string_view::basic_string_view(const basic_string_view& s)noexcept:
- m_data(s.m_data), m_length(s.m_length){}
- template
- constexpr basic_string_view::basic_string_view(const string_base& s)noexcept:
- m_data(s.c_str()), m_length(s.length()){}
- template
- constexpr basic_string_view::basic_string_view(basic_string_view&& s)noexcept:
- m_data(s.m_data), m_length(s.m_length){}
- template
- template
- constexpr basic_string_view::basic_string_view(InIter start, InIter fin)noexcept:
- basic_string_view(compat::to_address(start), fin - start){}
-
- template
- constexpr basic_string_view& basic_string_view::operator=(const basic_string_view& s)noexcept{
- m_data = s.m_data;
- m_length = s.m_length;
- return *this;
- }
- template
- constexpr basic_string_view::basic_string_view(const_pointer c)noexcept:
- basic_string_view(c, strlen(c)){}
- template