From acbabedf2753422821c4dddb204b8026173ece1e Mon Sep 17 00:00:00 2001 From: Justine Tunney Date: Mon, 1 Jul 2024 03:48:28 -0700 Subject: [PATCH] Make CTL definitions less ambiguous --- ctl/allocator_traits.h | 27 ++++++++-------------- ctl/bad_alloc.h | 2 +- ctl/decay.h | 15 ++++++------ ctl/distance.h | 12 ++++++---- ctl/is_abstract.h | 2 +- ctl/is_array.h | 6 ++--- ctl/is_base_of.h | 3 ++- ctl/is_class.h | 2 +- ctl/is_constructible.h | 2 +- ctl/is_convertible.h | 8 +++---- ctl/is_empty.h | 2 +- ctl/is_enum.h | 2 +- ctl/is_function.h | 50 ++++++++++++++++++++-------------------- ctl/is_integral.h | 32 ++++++++++++------------- ctl/is_polymorphic.h | 2 +- ctl/is_standard_layout.h | 2 +- ctl/is_trivial.h | 2 +- ctl/is_union.h | 2 +- ctl/istream.h | 2 +- ctl/istringstream.cc | 8 +++---- ctl/istringstream.h | 6 ++--- ctl/map.h | 24 +++++++++---------- ctl/mutex.h | 12 ++++++---- ctl/ostream.h | 2 +- ctl/ostringstream.cc | 20 ++++++++-------- ctl/ostringstream.h | 10 ++++---- ctl/out_of_range.h | 2 +- ctl/reverse_iterator.h | 11 +++++---- ctl/set.h | 29 ++++++++++++----------- ctl/string.h | 50 ++++++++++++++++++++-------------------- 30 files changed, 176 insertions(+), 173 deletions(-) diff --git a/ctl/allocator_traits.h b/ctl/allocator_traits.h index ebdf03424..4873899f4 100644 --- a/ctl/allocator_traits.h +++ b/ctl/allocator_traits.h @@ -18,10 +18,10 @@ struct allocator_traits using difference_type = typename Alloc::difference_type; using size_type = typename Alloc::size_type; - using propagate_on_container_copy_assignment = false_type; - using propagate_on_container_move_assignment = true_type; - using propagate_on_container_swap = false_type; - using is_always_equal = true_type; + using propagate_on_container_copy_assignment = ctl::false_type; + using propagate_on_container_move_assignment = ctl::true_type; + using propagate_on_container_swap = ctl::false_type; + using is_always_equal = ctl::true_type; template using rebind_alloc = typename Alloc::template rebind::other; @@ -29,41 +29,34 @@ struct allocator_traits template using rebind_traits = allocator_traits>; - __attribute__((__always_inline__)) static pointer allocate(Alloc& a, - size_type n) + static pointer allocate(Alloc& a, size_type n) { return a.allocate(n); } - __attribute__((__always_inline__)) static void deallocate(Alloc& a, - pointer p, - size_type n) + static void deallocate(Alloc& a, pointer p, size_type n) { a.deallocate(p, n); } template - __attribute__((__always_inline__)) static void construct(Alloc& a, - T* p, - Args&&... args) + static void construct(Alloc& a, T* p, Args&&... args) { ::new ((void*)p) T(static_cast(args)...); } template - __attribute__((__always_inline__)) static void destroy(Alloc& a, T* p) + static void destroy(Alloc& a, T* p) { p->~T(); } - __attribute__((__always_inline__)) static size_type max_size( - const Alloc& a) noexcept + static size_type max_size(const Alloc& a) noexcept { return __PTRDIFF_MAX__ / sizeof(value_type); } - __attribute__((__always_inline__)) static Alloc - select_on_container_copy_construction(const Alloc& a) + static Alloc select_on_container_copy_construction(const Alloc& a) { return a; } diff --git a/ctl/bad_alloc.h b/ctl/bad_alloc.h index 2f92578fe..99bcda0be 100644 --- a/ctl/bad_alloc.h +++ b/ctl/bad_alloc.h @@ -6,7 +6,7 @@ namespace ctl { -class bad_alloc : public exception +class bad_alloc : public ctl::exception { public: bad_alloc() noexcept = default; diff --git a/ctl/decay.h b/ctl/decay.h index 6c4fe6f2a..3944eeba0 100644 --- a/ctl/decay.h +++ b/ctl/decay.h @@ -16,15 +16,16 @@ template struct decay { private: - typedef typename remove_reference::type U; + typedef typename ctl::remove_reference::type U; public: - typedef typename conditional< - is_array::value, - typename remove_extent::type*, - typename conditional::value, - typename add_pointer::type, - typename remove_cv::type>::type>::type type; + typedef typename ctl::conditional< + ctl::is_array::value, + typename ctl::remove_extent::type*, + typename ctl::conditional::value, + typename ctl::add_pointer::type, + typename ctl::remove_cv::type>::type>::type + type; }; template diff --git a/ctl/distance.h b/ctl/distance.h index 83bac2a77..ab06867d9 100644 --- a/ctl/distance.h +++ b/ctl/distance.h @@ -8,28 +8,30 @@ namespace ctl { template -constexpr typename iterator_traits::difference_type +constexpr typename ctl::iterator_traits::difference_type distance_impl(InputIter first, InputIter last, input_iterator_tag) { - typename iterator_traits::difference_type res(0); + typename ctl::iterator_traits::difference_type res(0); for (; first != last; ++first) ++res; return res; } template -constexpr typename iterator_traits::difference_type +constexpr typename ctl::iterator_traits::difference_type distance_impl(RandIter first, RandIter last, random_access_iterator_tag) { return last - first; } template -constexpr typename iterator_traits::difference_type +constexpr typename ctl::iterator_traits::difference_type distance(InputIter first, InputIter last) { return distance_impl( - first, last, typename iterator_traits::iterator_category()); + first, + last, + typename ctl::iterator_traits::iterator_category()); } } // namespace ctl diff --git a/ctl/is_abstract.h b/ctl/is_abstract.h index ccd26c123..95360a5f4 100644 --- a/ctl/is_abstract.h +++ b/ctl/is_abstract.h @@ -7,7 +7,7 @@ namespace ctl { template -struct is_abstract : public integral_constant +struct is_abstract : public ctl::integral_constant {}; template diff --git a/ctl/is_array.h b/ctl/is_array.h index 946d152ea..4888b87a7 100644 --- a/ctl/is_array.h +++ b/ctl/is_array.h @@ -7,15 +7,15 @@ namespace ctl { template -struct is_array : false_type +struct is_array : ctl::false_type {}; template -struct is_array : true_type +struct is_array : ctl::true_type {}; template -struct is_array : true_type +struct is_array : ctl::true_type {}; template diff --git a/ctl/is_base_of.h b/ctl/is_base_of.h index a37456f26..82c9961c1 100644 --- a/ctl/is_base_of.h +++ b/ctl/is_base_of.h @@ -7,7 +7,8 @@ namespace ctl { template -struct is_base_of : public integral_constant +struct is_base_of + : public ctl::integral_constant {}; template diff --git a/ctl/is_class.h b/ctl/is_class.h index 3c958bd17..f5f78958e 100644 --- a/ctl/is_class.h +++ b/ctl/is_class.h @@ -7,7 +7,7 @@ namespace ctl { template -struct is_class : public integral_constant +struct is_class : public ctl::integral_constant {}; template diff --git a/ctl/is_constructible.h b/ctl/is_constructible.h index 4d202bdc5..0f3c3fce8 100644 --- a/ctl/is_constructible.h +++ b/ctl/is_constructible.h @@ -8,7 +8,7 @@ namespace ctl { template struct is_constructible - : public integral_constant + : public ctl::integral_constant {}; template diff --git a/ctl/is_convertible.h b/ctl/is_convertible.h index 69a105ad3..b485f5769 100644 --- a/ctl/is_convertible.h +++ b/ctl/is_convertible.h @@ -15,7 +15,7 @@ declval() noexcept; namespace detail { template -struct is_convertible_impl : false_type +struct is_convertible_impl : ctl::false_type {}; template @@ -27,15 +27,15 @@ struct is_convertible_impl -struct is_convertible_impl : true_type +struct is_convertible_impl : ctl::true_type {}; template -struct is_convertible_impl : false_type +struct is_convertible_impl : ctl::false_type {}; template -struct is_convertible_impl : false_type +struct is_convertible_impl : ctl::false_type {}; } // namespace detail diff --git a/ctl/is_empty.h b/ctl/is_empty.h index a1cf31675..095c069ea 100644 --- a/ctl/is_empty.h +++ b/ctl/is_empty.h @@ -7,7 +7,7 @@ namespace ctl { template -struct is_empty : public integral_constant +struct is_empty : public ctl::integral_constant {}; template diff --git a/ctl/is_enum.h b/ctl/is_enum.h index 7d2cd5b78..19adcd8c3 100644 --- a/ctl/is_enum.h +++ b/ctl/is_enum.h @@ -7,7 +7,7 @@ namespace ctl { template -struct is_enum : public integral_constant +struct is_enum : public ctl::integral_constant {}; template diff --git a/ctl/is_function.h b/ctl/is_function.h index 667a1e8eb..bee4f85f8 100644 --- a/ctl/is_function.h +++ b/ctl/is_function.h @@ -8,111 +8,111 @@ namespace ctl { // Primary template template -struct is_function : false_type +struct is_function : ctl::false_type {}; // Specializations for various function types // Regular functions template -struct is_function : true_type +struct is_function : ctl::true_type {}; // Functions with cv-qualifiers template -struct is_function : true_type +struct is_function : ctl::true_type {}; template -struct is_function : true_type +struct is_function : ctl::true_type {}; template -struct is_function : true_type +struct is_function : ctl::true_type {}; // Functions with ref-qualifiers template -struct is_function : true_type +struct is_function : ctl::true_type {}; template -struct is_function : true_type +struct is_function : ctl::true_type {}; template -struct is_function : true_type +struct is_function : ctl::true_type {}; template -struct is_function : true_type +struct is_function : ctl::true_type {}; template -struct is_function : true_type +struct is_function : ctl::true_type {}; template -struct is_function : true_type +struct is_function : ctl::true_type {}; template -struct is_function : true_type +struct is_function : ctl::true_type {}; template -struct is_function : true_type +struct is_function : ctl::true_type {}; // Variadic functions template -struct is_function : true_type +struct is_function : ctl::true_type {}; // Variadic functions with cv-qualifiers template -struct is_function : true_type +struct is_function : ctl::true_type {}; template -struct is_function : true_type +struct is_function : ctl::true_type {}; template -struct is_function : true_type +struct is_function : ctl::true_type {}; // Variadic functions with ref-qualifiers template -struct is_function : true_type +struct is_function : ctl::true_type {}; template -struct is_function : true_type +struct is_function : ctl::true_type {}; template -struct is_function : true_type +struct is_function : ctl::true_type {}; template -struct is_function : true_type +struct is_function : ctl::true_type {}; template -struct is_function : true_type +struct is_function : ctl::true_type {}; template -struct is_function : true_type +struct is_function : ctl::true_type {}; template -struct is_function : true_type +struct is_function : ctl::true_type {}; template -struct is_function : true_type +struct is_function : ctl::true_type {}; } // namespace ctl diff --git a/ctl/is_integral.h b/ctl/is_integral.h index 384985a38..a68344119 100644 --- a/ctl/is_integral.h +++ b/ctl/is_integral.h @@ -7,67 +7,67 @@ namespace ctl { template -struct is_integral : false_type +struct is_integral : ctl::false_type {}; template<> -struct is_integral : true_type +struct is_integral : ctl::true_type {}; template<> -struct is_integral : true_type +struct is_integral : ctl::true_type {}; template<> -struct is_integral : true_type +struct is_integral : ctl::true_type {}; template<> -struct is_integral : true_type +struct is_integral : ctl::true_type {}; template<> -struct is_integral : true_type +struct is_integral : ctl::true_type {}; template<> -struct is_integral : true_type +struct is_integral : ctl::true_type {}; template<> -struct is_integral : true_type +struct is_integral : ctl::true_type {}; template<> -struct is_integral : true_type +struct is_integral : ctl::true_type {}; template<> -struct is_integral : true_type +struct is_integral : ctl::true_type {}; template<> -struct is_integral : true_type +struct is_integral : ctl::true_type {}; template<> -struct is_integral : true_type +struct is_integral : ctl::true_type {}; template<> -struct is_integral : true_type +struct is_integral : ctl::true_type {}; template<> -struct is_integral : true_type +struct is_integral : ctl::true_type {}; template<> -struct is_integral : true_type +struct is_integral : ctl::true_type {}; template<> -struct is_integral : true_type +struct is_integral : ctl::true_type {}; template diff --git a/ctl/is_polymorphic.h b/ctl/is_polymorphic.h index 152b7af0b..499862d1d 100644 --- a/ctl/is_polymorphic.h +++ b/ctl/is_polymorphic.h @@ -7,7 +7,7 @@ namespace ctl { template -struct is_polymorphic : public integral_constant +struct is_polymorphic : public ctl::integral_constant {}; template diff --git a/ctl/is_standard_layout.h b/ctl/is_standard_layout.h index 59ae380c8..0eabab88f 100644 --- a/ctl/is_standard_layout.h +++ b/ctl/is_standard_layout.h @@ -8,7 +8,7 @@ namespace ctl { template struct is_standard_layout - : public integral_constant + : public ctl::integral_constant {}; template diff --git a/ctl/is_trivial.h b/ctl/is_trivial.h index c69c18f08..f2e996bcf 100644 --- a/ctl/is_trivial.h +++ b/ctl/is_trivial.h @@ -7,7 +7,7 @@ namespace ctl { template -struct is_trivial : public integral_constant +struct is_trivial : public ctl::integral_constant {}; template diff --git a/ctl/is_union.h b/ctl/is_union.h index 773c52e3b..ebae27125 100644 --- a/ctl/is_union.h +++ b/ctl/is_union.h @@ -7,7 +7,7 @@ namespace ctl { template -struct is_union : public integral_constant +struct is_union : public ctl::integral_constant {}; template diff --git a/ctl/istream.h b/ctl/istream.h index 2ec23284d..f80bc5bf0 100644 --- a/ctl/istream.h +++ b/ctl/istream.h @@ -20,7 +20,7 @@ class istream : public ios istream& operator>>(long&); istream& operator>>(double&); istream& operator>>(bool&); - istream& operator>>(string&); + istream& operator>>(ctl::string&); istream& operator>>(istream& (*)(istream&)); int get(); diff --git a/ctl/istringstream.cc b/ctl/istringstream.cc index 5674c620a..bfaed7a37 100644 --- a/ctl/istringstream.cc +++ b/ctl/istringstream.cc @@ -26,19 +26,19 @@ istringstream::istringstream() : buffer_(), read_pos_(0) { } -istringstream::istringstream(const string_view& str) +istringstream::istringstream(const ctl::string_view& str) : buffer_(str), read_pos_(0) { } -string +ctl::string istringstream::str() const { return buffer_; } void -istringstream::str(const string& s) +istringstream::str(const ctl::string& s) { buffer_ = s; read_pos_ = 0; @@ -82,7 +82,7 @@ istringstream::operator>>(char* s) } istringstream& -istringstream::operator>>(string& s) +istringstream::operator>>(ctl::string& s) { if (!good()) return *this; diff --git a/ctl/istringstream.h b/ctl/istringstream.h index b3c95e3d7..0ced67333 100644 --- a/ctl/istringstream.h +++ b/ctl/istringstream.h @@ -11,14 +11,14 @@ class istringstream : public ios_base { public: istringstream(); - explicit istringstream(const string_view&); + explicit istringstream(const ctl::string_view&); string str() const; void str(const string&); istringstream& operator>>(char&); istringstream& operator>>(char*); - istringstream& operator>>(string&); + istringstream& operator>>(ctl::string&); istringstream& operator>>(short&); istringstream& operator>>(unsigned short&); istringstream& operator>>(int&); @@ -29,7 +29,7 @@ class istringstream : public ios_base istringstream& operator>>(double&); private: - string buffer_; + ctl::string buffer_; size_t read_pos_; template diff --git a/ctl/map.h b/ctl/map.h index e3978545e..32c98d5e1 100644 --- a/ctl/map.h +++ b/ctl/map.h @@ -152,12 +152,12 @@ class map Value& operator[](const Key& key) { - return ((data_.insert(make_pair(key, Value()))).first)->second; + return ((data_.insert(ctl::make_pair(key, Value()))).first)->second; } Value& operator[](Key&& key) { - return ((data_.insert(make_pair(ctl::move(key), Value()))).first) + return ((data_.insert(ctl::make_pair(ctl::move(key), Value()))).first) ->second; } @@ -244,7 +244,7 @@ class map size_type erase(const Key& key) { - return data_.erase(make_pair(key, Value())); + return data_.erase(ctl::make_pair(key, Value())); } void swap(map& other) noexcept @@ -259,47 +259,47 @@ class map iterator find(const Key& key) { - return data_.find(make_pair(key, Value())); + return data_.find(ctl::make_pair(key, Value())); } const_iterator find(const Key& key) const { - return data_.find(make_pair(key, Value())); + return data_.find(ctl::make_pair(key, Value())); } size_type count(const Key& key) const { - return data_.count(make_pair(key, Value())); + return data_.count(ctl::make_pair(key, Value())); } iterator lower_bound(const Key& key) { - return data_.lower_bound(make_pair(key, Value())); + return data_.lower_bound(ctl::make_pair(key, Value())); } const_iterator lower_bound(const Key& key) const { - return data_.lower_bound(make_pair(key, Value())); + return data_.lower_bound(ctl::make_pair(key, Value())); } iterator upper_bound(const Key& key) { - return data_.upper_bound(make_pair(key, Value())); + return data_.upper_bound(ctl::make_pair(key, Value())); } const_iterator upper_bound(const Key& key) const { - return data_.upper_bound(make_pair(key, Value())); + return data_.upper_bound(ctl::make_pair(key, Value())); } ctl::pair equal_range(const Key& key) { - return data_.equal_range(make_pair(key, Value())); + return data_.equal_range(ctl::make_pair(key, Value())); } ctl::pair equal_range(const Key& key) const { - return data_.equal_range(make_pair(key, Value())); + return data_.equal_range(ctl::make_pair(key, Value())); } key_compare key_comp() const diff --git a/ctl/mutex.h b/ctl/mutex.h index 28a21e2e7..19f67a82a 100644 --- a/ctl/mutex.h +++ b/ctl/mutex.h @@ -11,17 +11,20 @@ class mutex public: mutex() { - pthread_mutex_init(&m_, nullptr); + if (pthread_mutex_init(&m_, nullptr)) + __builtin_trap(); } ~mutex() { - pthread_mutex_destroy(&m_); + if (pthread_mutex_destroy(&m_)) + __builtin_trap(); } void lock() { - pthread_mutex_lock(&m_); + if (pthread_mutex_lock(&m_)) + __builtin_trap(); } bool try_lock() @@ -31,7 +34,8 @@ class mutex void unlock() { - pthread_mutex_unlock(&m_); + if (pthread_mutex_unlock(&m_)) + __builtin_trap(); } // Delete copy constructor and assignment operator diff --git a/ctl/ostream.h b/ctl/ostream.h index 3b30421a1..6529db5b9 100644 --- a/ctl/ostream.h +++ b/ctl/ostream.h @@ -20,7 +20,7 @@ class ostream : public ios ostream& operator<<(int); ostream& operator<<(long); ostream& operator<<(double); - ostream& operator<<(const string_view&); + ostream& operator<<(const ctl::string_view&); ostream& operator<<(bool); ostream& operator<<(ostream& (*)(ostream&)); diff --git a/ctl/ostringstream.cc b/ctl/ostringstream.cc index b322c01e8..eb7fa51cc 100644 --- a/ctl/ostringstream.cc +++ b/ctl/ostringstream.cc @@ -26,19 +26,19 @@ ostringstream::ostringstream() : buffer_(), write_pos_(0) { } -ostringstream::ostringstream(const string_view& str) +ostringstream::ostringstream(const ctl::string_view& str) : buffer_(str), write_pos_(0) { } -string +ctl::string ostringstream::str() const { return buffer_; } void -ostringstream::str(const string& s) +ostringstream::str(const ctl::string& s) { buffer_ = s; write_pos_ = 0; @@ -65,7 +65,7 @@ ostringstream::operator<<(char c) } ostringstream& -ostringstream::operator<<(const string_view& s) +ostringstream::operator<<(const ctl::string_view& s) { if (good()) { if (write_pos_ + s.size() <= buffer_.size()) { @@ -84,7 +84,7 @@ ostringstream::operator<<(int n) { char temp[12]; if (good()) - *this << string_view(temp, FormatInt32(temp, n) - temp); + *this << ctl::string_view(temp, FormatInt32(temp, n) - temp); return *this; } @@ -93,7 +93,7 @@ ostringstream::operator<<(unsigned int n) { char temp[12]; if (good()) - *this << string_view(temp, FormatUint32(temp, n) - temp); + *this << ctl::string_view(temp, FormatUint32(temp, n) - temp); return *this; } @@ -102,7 +102,7 @@ ostringstream::operator<<(long n) { char temp[21]; if (good()) - *this << string_view(temp, FormatInt64(temp, n) - temp); + *this << ctl::string_view(temp, FormatInt64(temp, n) - temp); return *this; } @@ -111,7 +111,7 @@ ostringstream::operator<<(unsigned long n) { char temp[21]; if (good()) - *this << string_view(temp, FormatUint64(temp, n) - temp); + *this << ctl::string_view(temp, FormatUint64(temp, n) - temp); return *this; } @@ -121,7 +121,7 @@ ostringstream::operator<<(float f) if (good()) { char temp[32]; int len = snprintf(temp, sizeof(temp), "%g", f); - *this << string_view(temp, len); + *this << ctl::string_view(temp, len); } return *this; } @@ -132,7 +132,7 @@ ostringstream::operator<<(double d) if (good()) { char temp[32]; int len = snprintf(temp, sizeof(temp), "%g", d); - *this << string_view(temp, len); + *this << ctl::string_view(temp, len); } return *this; } diff --git a/ctl/ostringstream.h b/ctl/ostringstream.h index 09face624..46ca777fe 100644 --- a/ctl/ostringstream.h +++ b/ctl/ostringstream.h @@ -11,14 +11,14 @@ class ostringstream : public ios_base { public: ostringstream(); - explicit ostringstream(const string_view&); + explicit ostringstream(const ctl::string_view&); - string str() const; - void str(const string& s); + ctl::string str() const; + void str(const ctl::string& s); void clear(); ostringstream& operator<<(char); - ostringstream& operator<<(const string_view&); + ostringstream& operator<<(const ctl::string_view&); ostringstream& operator<<(int); ostringstream& operator<<(unsigned int); ostringstream& operator<<(long); @@ -27,7 +27,7 @@ class ostringstream : public ios_base ostringstream& operator<<(double); private: - string buffer_; + ctl::string buffer_; size_t write_pos_; }; diff --git a/ctl/out_of_range.h b/ctl/out_of_range.h index 08c65fc18..27b76e82d 100644 --- a/ctl/out_of_range.h +++ b/ctl/out_of_range.h @@ -6,7 +6,7 @@ namespace ctl { -class out_of_range : public exception +class out_of_range : public ctl::exception { public: out_of_range() noexcept = default; diff --git a/ctl/reverse_iterator.h b/ctl/reverse_iterator.h index b7d0245cd..67d5c23ea 100644 --- a/ctl/reverse_iterator.h +++ b/ctl/reverse_iterator.h @@ -13,11 +13,12 @@ class reverse_iterator public: using iterator_type = Iterator; using iterator_category = - typename iterator_traits::iterator_category; - using value_type = typename iterator_traits::value_type; - using difference_type = typename iterator_traits::difference_type; - using pointer = typename iterator_traits::pointer; - using reference = typename iterator_traits::reference; + typename ctl::iterator_traits::iterator_category; + using value_type = typename ctl::iterator_traits::value_type; + using difference_type = + typename ctl::iterator_traits::difference_type; + using pointer = typename ctl::iterator_traits::pointer; + using reference = typename ctl::iterator_traits::reference; constexpr reverse_iterator() : current() { diff --git a/ctl/set.h b/ctl/set.h index 94644d267..ef7ee74bf 100644 --- a/ctl/set.h +++ b/ctl/set.h @@ -8,7 +8,7 @@ namespace ctl { -template> +template> class set { struct rbtree @@ -381,12 +381,12 @@ class set size_ = 0; } - pair insert(value_type&& value) + ctl::pair insert(value_type&& value) { return insert_node(new node_type(ctl::move(value))); } - pair insert(const value_type& value) + ctl::pair insert(const value_type& value) { return insert_node(new node_type(value)); } @@ -415,7 +415,7 @@ class set } template - pair emplace(Args&&... args) + ctl::pair emplace(Args&&... args) { value_type value(ctl::forward(args)...); return insert(ctl::move(value)); @@ -451,12 +451,13 @@ class set ctl::swap(size_, other.size_); } - pair equal_range(const key_type& key) + ctl::pair equal_range(const key_type& key) { return { iterator(get_floor(key)), iterator(get_ceiling(key)) }; } - pair equal_range(const key_type& key) const + ctl::pair equal_range( + const key_type& key) const { return { const_iterator(get_floor(key)), const_iterator(get_ceiling(key)) }; @@ -613,7 +614,7 @@ class set return result; } - pair insert_node(node_type* node) + ctl::pair insert_node(node_type* node) { if (root_ == nullptr) { root_ = node; @@ -878,7 +879,7 @@ class set Compare comp_; }; -template> +template> bool operator==(const set& lhs, const set& rhs) { @@ -893,7 +894,7 @@ operator==(const set& lhs, const set& rhs) return true; } -template> +template> bool operator<(const set& lhs, const set& rhs) { @@ -908,35 +909,35 @@ operator<(const set& lhs, const set& rhs) return i == lhs.end() && j != rhs.end(); } -template> +template> bool operator!=(const set& lhs, const set& rhs) { return !(lhs == rhs); } -template> +template> bool operator<=(const set& lhs, const set& rhs) { return !(rhs < lhs); } -template> +template> bool operator>(const set& lhs, const set& rhs) { return rhs < lhs; } -template> +template> bool operator>=(const set& lhs, const set& rhs) { return !(lhs < rhs); } -template> +template> void swap(set& lhs, set& rhs) noexcept; diff --git a/ctl/string.h b/ctl/string.h index ba0ee6223..0509f3839 100644 --- a/ctl/string.h +++ b/ctl/string.h @@ -9,7 +9,7 @@ namespace ctl { class string; -string strcat(string_view, string_view) noexcept __wur; +ctl::string strcat(ctl::string_view, ctl::string_view) noexcept __wur; namespace __ { @@ -66,7 +66,7 @@ class string *(((size_t*)blob) + 2) = __::sso_max << (sizeof(size_t) - 1) * 8; } - string(const string_view s) noexcept + string(const ctl::string_view s) noexcept { if (s.n <= __::sso_max) { __builtin_memcpy(blob, s.p, s.n); @@ -89,7 +89,7 @@ class string } string(const char* const p) noexcept - : string(string_view(p, __builtin_strlen(p))) + : string(ctl::string_view(p, __builtin_strlen(p))) { } @@ -104,7 +104,7 @@ class string } string(const char* const p, const size_t n) noexcept - : string(string_view(p, n)) + : string(ctl::string_view(p, n)) { } @@ -125,17 +125,17 @@ class string void append(char, size_t) noexcept; void append(unsigned long) noexcept; void append(const void*, size_t) noexcept; - string& insert(size_t, string_view) noexcept; + string& insert(size_t, ctl::string_view) noexcept; string& erase(size_t = 0, size_t = npos) noexcept; string substr(size_t = 0, size_t = npos) const noexcept; - string& replace(size_t, size_t, string_view) noexcept; - bool operator==(string_view) const noexcept; - bool operator!=(string_view) const noexcept; - bool contains(string_view) const noexcept; - bool ends_with(string_view) const noexcept; - bool starts_with(string_view) const noexcept; + string& replace(size_t, size_t, ctl::string_view) noexcept; + bool operator==(ctl::string_view) const noexcept; + bool operator!=(ctl::string_view) const noexcept; + bool contains(ctl::string_view) const noexcept; + bool ends_with(ctl::string_view) const noexcept; + bool starts_with(ctl::string_view) const noexcept; size_t find(char, size_t = 0) const noexcept; - size_t find(string_view, size_t = 0) const noexcept; + size_t find(ctl::string_view, size_t = 0) const noexcept; void swap(string& s) noexcept { @@ -302,14 +302,14 @@ class string append(ch); } - void append(const string_view s) noexcept + void append(const ctl::string_view s) noexcept { append(s.p, s.n); } - operator string_view() const noexcept + operator ctl::string_view() const noexcept { - return string_view(data(), size()); + return ctl::string_view(data(), size()); } string& operator=(const char* s) noexcept @@ -319,7 +319,7 @@ class string return *this; } - string& operator=(const string_view s) noexcept + string& operator=(const ctl::string_view s) noexcept { clear(); append(s); @@ -332,38 +332,38 @@ class string return *this; } - string& operator+=(const string_view s) noexcept + string& operator+=(const ctl::string_view s) noexcept { append(s); return *this; } - string operator+(const string_view s) const noexcept + string operator+(const ctl::string_view s) const noexcept { return strcat(*this, s); } - int compare(const string_view s) const noexcept + int compare(const ctl::string_view s) const noexcept { return strcmp(*this, s); } - bool operator<(const string_view s) const noexcept + bool operator<(const ctl::string_view s) const noexcept { return compare(s) < 0; } - bool operator<=(const string_view s) const noexcept + bool operator<=(const ctl::string_view s) const noexcept { return compare(s) <= 0; } - bool operator>(const string_view s) const noexcept + bool operator>(const ctl::string_view s) const noexcept { return compare(s) > 0; } - bool operator>=(const string_view s) const noexcept + bool operator>=(const ctl::string_view s) const noexcept { return compare(s) >= 0; } @@ -371,7 +371,7 @@ class string private: void destroy_big() noexcept; void init_big(const string&) noexcept; - void init_big(string_view) noexcept; + void init_big(ctl::string_view) noexcept; void init_big(size_t, char) noexcept; __attribute__((__always_inline__)) bool isbig() const noexcept @@ -395,7 +395,7 @@ class string __b.c = c2 | ~__::big_mask; } - friend string strcat(string_view, string_view) noexcept; + friend string strcat(ctl::string_view, ctl::string_view) noexcept; union {