mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-02-07 06:53:33 +00:00
Make CTL definitions less ambiguous
This commit is contained in:
parent
239f8ce76e
commit
acbabedf27
30 changed files with 176 additions and 173 deletions
|
@ -18,10 +18,10 @@ struct allocator_traits
|
||||||
using difference_type = typename Alloc::difference_type;
|
using difference_type = typename Alloc::difference_type;
|
||||||
using size_type = typename Alloc::size_type;
|
using size_type = typename Alloc::size_type;
|
||||||
|
|
||||||
using propagate_on_container_copy_assignment = false_type;
|
using propagate_on_container_copy_assignment = ctl::false_type;
|
||||||
using propagate_on_container_move_assignment = true_type;
|
using propagate_on_container_move_assignment = ctl::true_type;
|
||||||
using propagate_on_container_swap = false_type;
|
using propagate_on_container_swap = ctl::false_type;
|
||||||
using is_always_equal = true_type;
|
using is_always_equal = ctl::true_type;
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
using rebind_alloc = typename Alloc::template rebind<T>::other;
|
using rebind_alloc = typename Alloc::template rebind<T>::other;
|
||||||
|
@ -29,41 +29,34 @@ struct allocator_traits
|
||||||
template<typename T>
|
template<typename T>
|
||||||
using rebind_traits = allocator_traits<rebind_alloc<T>>;
|
using rebind_traits = allocator_traits<rebind_alloc<T>>;
|
||||||
|
|
||||||
__attribute__((__always_inline__)) static pointer allocate(Alloc& a,
|
static pointer allocate(Alloc& a, size_type n)
|
||||||
size_type n)
|
|
||||||
{
|
{
|
||||||
return a.allocate(n);
|
return a.allocate(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((__always_inline__)) static void deallocate(Alloc& a,
|
static void deallocate(Alloc& a, pointer p, size_type n)
|
||||||
pointer p,
|
|
||||||
size_type n)
|
|
||||||
{
|
{
|
||||||
a.deallocate(p, n);
|
a.deallocate(p, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T, typename... Args>
|
template<typename T, typename... Args>
|
||||||
__attribute__((__always_inline__)) static void construct(Alloc& a,
|
static void construct(Alloc& a, T* p, Args&&... args)
|
||||||
T* p,
|
|
||||||
Args&&... args)
|
|
||||||
{
|
{
|
||||||
::new ((void*)p) T(static_cast<Args&&>(args)...);
|
::new ((void*)p) T(static_cast<Args&&>(args)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
__attribute__((__always_inline__)) static void destroy(Alloc& a, T* p)
|
static void destroy(Alloc& a, T* p)
|
||||||
{
|
{
|
||||||
p->~T();
|
p->~T();
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((__always_inline__)) static size_type max_size(
|
static size_type max_size(const Alloc& a) noexcept
|
||||||
const Alloc& a) noexcept
|
|
||||||
{
|
{
|
||||||
return __PTRDIFF_MAX__ / sizeof(value_type);
|
return __PTRDIFF_MAX__ / sizeof(value_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((__always_inline__)) static Alloc
|
static Alloc select_on_container_copy_construction(const Alloc& a)
|
||||||
select_on_container_copy_construction(const Alloc& a)
|
|
||||||
{
|
{
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
namespace ctl {
|
namespace ctl {
|
||||||
|
|
||||||
class bad_alloc : public exception
|
class bad_alloc : public ctl::exception
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
bad_alloc() noexcept = default;
|
bad_alloc() noexcept = default;
|
||||||
|
|
15
ctl/decay.h
15
ctl/decay.h
|
@ -16,15 +16,16 @@ template<typename T>
|
||||||
struct decay
|
struct decay
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
typedef typename remove_reference<T>::type U;
|
typedef typename ctl::remove_reference<T>::type U;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
typedef typename conditional<
|
typedef typename ctl::conditional<
|
||||||
is_array<U>::value,
|
ctl::is_array<U>::value,
|
||||||
typename remove_extent<U>::type*,
|
typename ctl::remove_extent<U>::type*,
|
||||||
typename conditional<is_function<U>::value,
|
typename ctl::conditional<ctl::is_function<U>::value,
|
||||||
typename add_pointer<U>::type,
|
typename ctl::add_pointer<U>::type,
|
||||||
typename remove_cv<U>::type>::type>::type type;
|
typename ctl::remove_cv<U>::type>::type>::type
|
||||||
|
type;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
|
|
@ -8,28 +8,30 @@
|
||||||
namespace ctl {
|
namespace ctl {
|
||||||
|
|
||||||
template<class InputIter>
|
template<class InputIter>
|
||||||
constexpr typename iterator_traits<InputIter>::difference_type
|
constexpr typename ctl::iterator_traits<InputIter>::difference_type
|
||||||
distance_impl(InputIter first, InputIter last, input_iterator_tag)
|
distance_impl(InputIter first, InputIter last, input_iterator_tag)
|
||||||
{
|
{
|
||||||
typename iterator_traits<InputIter>::difference_type res(0);
|
typename ctl::iterator_traits<InputIter>::difference_type res(0);
|
||||||
for (; first != last; ++first)
|
for (; first != last; ++first)
|
||||||
++res;
|
++res;
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class RandIter>
|
template<class RandIter>
|
||||||
constexpr typename iterator_traits<RandIter>::difference_type
|
constexpr typename ctl::iterator_traits<RandIter>::difference_type
|
||||||
distance_impl(RandIter first, RandIter last, random_access_iterator_tag)
|
distance_impl(RandIter first, RandIter last, random_access_iterator_tag)
|
||||||
{
|
{
|
||||||
return last - first;
|
return last - first;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class InputIter>
|
template<class InputIter>
|
||||||
constexpr typename iterator_traits<InputIter>::difference_type
|
constexpr typename ctl::iterator_traits<InputIter>::difference_type
|
||||||
distance(InputIter first, InputIter last)
|
distance(InputIter first, InputIter last)
|
||||||
{
|
{
|
||||||
return distance_impl(
|
return distance_impl(
|
||||||
first, last, typename iterator_traits<InputIter>::iterator_category());
|
first,
|
||||||
|
last,
|
||||||
|
typename ctl::iterator_traits<InputIter>::iterator_category());
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace ctl
|
} // namespace ctl
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
namespace ctl {
|
namespace ctl {
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct is_abstract : public integral_constant<bool, __is_abstract(T)>
|
struct is_abstract : public ctl::integral_constant<bool, __is_abstract(T)>
|
||||||
{};
|
{};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
|
|
@ -7,15 +7,15 @@
|
||||||
namespace ctl {
|
namespace ctl {
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct is_array : false_type
|
struct is_array : ctl::false_type
|
||||||
{};
|
{};
|
||||||
|
|
||||||
template<typename T, size_t N>
|
template<typename T, size_t N>
|
||||||
struct is_array<T[N]> : true_type
|
struct is_array<T[N]> : ctl::true_type
|
||||||
{};
|
{};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct is_array<T[]> : true_type
|
struct is_array<T[]> : ctl::true_type
|
||||||
{};
|
{};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
|
|
@ -7,7 +7,8 @@
|
||||||
namespace ctl {
|
namespace ctl {
|
||||||
|
|
||||||
template<typename Base, typename Derived>
|
template<typename Base, typename Derived>
|
||||||
struct is_base_of : public integral_constant<bool, __is_base_of(Base, Derived)>
|
struct is_base_of
|
||||||
|
: public ctl::integral_constant<bool, __is_base_of(Base, Derived)>
|
||||||
{};
|
{};
|
||||||
|
|
||||||
template<typename Base, typename Derived>
|
template<typename Base, typename Derived>
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
namespace ctl {
|
namespace ctl {
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct is_class : public integral_constant<bool, __is_class(T)>
|
struct is_class : public ctl::integral_constant<bool, __is_class(T)>
|
||||||
{};
|
{};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
|
|
@ -8,7 +8,7 @@ namespace ctl {
|
||||||
|
|
||||||
template<class _Tp, class... _Args>
|
template<class _Tp, class... _Args>
|
||||||
struct is_constructible
|
struct is_constructible
|
||||||
: public integral_constant<bool, __is_constructible(_Tp, _Args...)>
|
: public ctl::integral_constant<bool, __is_constructible(_Tp, _Args...)>
|
||||||
{};
|
{};
|
||||||
|
|
||||||
template<class _Tp, class... _Args>
|
template<class _Tp, class... _Args>
|
||||||
|
|
|
@ -15,7 +15,7 @@ declval() noexcept;
|
||||||
namespace detail {
|
namespace detail {
|
||||||
|
|
||||||
template<typename From, typename To, typename = void>
|
template<typename From, typename To, typename = void>
|
||||||
struct is_convertible_impl : false_type
|
struct is_convertible_impl : ctl::false_type
|
||||||
{};
|
{};
|
||||||
|
|
||||||
template<typename From, typename To>
|
template<typename From, typename To>
|
||||||
|
@ -27,15 +27,15 @@ struct is_convertible_impl<From,
|
||||||
|
|
||||||
// Handle void types separately
|
// Handle void types separately
|
||||||
template<>
|
template<>
|
||||||
struct is_convertible_impl<void, void> : true_type
|
struct is_convertible_impl<void, void> : ctl::true_type
|
||||||
{};
|
{};
|
||||||
|
|
||||||
template<typename To>
|
template<typename To>
|
||||||
struct is_convertible_impl<void, To> : false_type
|
struct is_convertible_impl<void, To> : ctl::false_type
|
||||||
{};
|
{};
|
||||||
|
|
||||||
template<typename From>
|
template<typename From>
|
||||||
struct is_convertible_impl<From, void> : false_type
|
struct is_convertible_impl<From, void> : ctl::false_type
|
||||||
{};
|
{};
|
||||||
|
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
namespace ctl {
|
namespace ctl {
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct is_empty : public integral_constant<bool, __is_empty(T)>
|
struct is_empty : public ctl::integral_constant<bool, __is_empty(T)>
|
||||||
{};
|
{};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
namespace ctl {
|
namespace ctl {
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct is_enum : public integral_constant<bool, __is_enum(T)>
|
struct is_enum : public ctl::integral_constant<bool, __is_enum(T)>
|
||||||
{};
|
{};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
|
|
@ -8,111 +8,111 @@ namespace ctl {
|
||||||
|
|
||||||
// Primary template
|
// Primary template
|
||||||
template<class>
|
template<class>
|
||||||
struct is_function : false_type
|
struct is_function : ctl::false_type
|
||||||
{};
|
{};
|
||||||
|
|
||||||
// Specializations for various function types
|
// Specializations for various function types
|
||||||
|
|
||||||
// Regular functions
|
// Regular functions
|
||||||
template<class Ret, class... Args>
|
template<class Ret, class... Args>
|
||||||
struct is_function<Ret(Args...)> : true_type
|
struct is_function<Ret(Args...)> : ctl::true_type
|
||||||
{};
|
{};
|
||||||
|
|
||||||
// Functions with cv-qualifiers
|
// Functions with cv-qualifiers
|
||||||
template<class Ret, class... Args>
|
template<class Ret, class... Args>
|
||||||
struct is_function<Ret(Args...) const> : true_type
|
struct is_function<Ret(Args...) const> : ctl::true_type
|
||||||
{};
|
{};
|
||||||
|
|
||||||
template<class Ret, class... Args>
|
template<class Ret, class... Args>
|
||||||
struct is_function<Ret(Args...) volatile> : true_type
|
struct is_function<Ret(Args...) volatile> : ctl::true_type
|
||||||
{};
|
{};
|
||||||
|
|
||||||
template<class Ret, class... Args>
|
template<class Ret, class... Args>
|
||||||
struct is_function<Ret(Args...) const volatile> : true_type
|
struct is_function<Ret(Args...) const volatile> : ctl::true_type
|
||||||
{};
|
{};
|
||||||
|
|
||||||
// Functions with ref-qualifiers
|
// Functions with ref-qualifiers
|
||||||
template<class Ret, class... Args>
|
template<class Ret, class... Args>
|
||||||
struct is_function<Ret(Args...)&> : true_type
|
struct is_function<Ret(Args...)&> : ctl::true_type
|
||||||
{};
|
{};
|
||||||
|
|
||||||
template<class Ret, class... Args>
|
template<class Ret, class... Args>
|
||||||
struct is_function<Ret(Args...) const&> : true_type
|
struct is_function<Ret(Args...) const&> : ctl::true_type
|
||||||
{};
|
{};
|
||||||
|
|
||||||
template<class Ret, class... Args>
|
template<class Ret, class... Args>
|
||||||
struct is_function<Ret(Args...) volatile&> : true_type
|
struct is_function<Ret(Args...) volatile&> : ctl::true_type
|
||||||
{};
|
{};
|
||||||
|
|
||||||
template<class Ret, class... Args>
|
template<class Ret, class... Args>
|
||||||
struct is_function<Ret(Args...) const volatile&> : true_type
|
struct is_function<Ret(Args...) const volatile&> : ctl::true_type
|
||||||
{};
|
{};
|
||||||
|
|
||||||
template<class Ret, class... Args>
|
template<class Ret, class... Args>
|
||||||
struct is_function<Ret(Args...) &&> : true_type
|
struct is_function<Ret(Args...) &&> : ctl::true_type
|
||||||
{};
|
{};
|
||||||
|
|
||||||
template<class Ret, class... Args>
|
template<class Ret, class... Args>
|
||||||
struct is_function<Ret(Args...) const&&> : true_type
|
struct is_function<Ret(Args...) const&&> : ctl::true_type
|
||||||
{};
|
{};
|
||||||
|
|
||||||
template<class Ret, class... Args>
|
template<class Ret, class... Args>
|
||||||
struct is_function<Ret(Args...) volatile&&> : true_type
|
struct is_function<Ret(Args...) volatile&&> : ctl::true_type
|
||||||
{};
|
{};
|
||||||
|
|
||||||
template<class Ret, class... Args>
|
template<class Ret, class... Args>
|
||||||
struct is_function<Ret(Args...) const volatile&&> : true_type
|
struct is_function<Ret(Args...) const volatile&&> : ctl::true_type
|
||||||
{};
|
{};
|
||||||
|
|
||||||
// Variadic functions
|
// Variadic functions
|
||||||
template<class Ret, class... Args>
|
template<class Ret, class... Args>
|
||||||
struct is_function<Ret(Args..., ...)> : true_type
|
struct is_function<Ret(Args..., ...)> : ctl::true_type
|
||||||
{};
|
{};
|
||||||
|
|
||||||
// Variadic functions with cv-qualifiers
|
// Variadic functions with cv-qualifiers
|
||||||
template<class Ret, class... Args>
|
template<class Ret, class... Args>
|
||||||
struct is_function<Ret(Args..., ...) const> : true_type
|
struct is_function<Ret(Args..., ...) const> : ctl::true_type
|
||||||
{};
|
{};
|
||||||
|
|
||||||
template<class Ret, class... Args>
|
template<class Ret, class... Args>
|
||||||
struct is_function<Ret(Args..., ...) volatile> : true_type
|
struct is_function<Ret(Args..., ...) volatile> : ctl::true_type
|
||||||
{};
|
{};
|
||||||
|
|
||||||
template<class Ret, class... Args>
|
template<class Ret, class... Args>
|
||||||
struct is_function<Ret(Args..., ...) const volatile> : true_type
|
struct is_function<Ret(Args..., ...) const volatile> : ctl::true_type
|
||||||
{};
|
{};
|
||||||
|
|
||||||
// Variadic functions with ref-qualifiers
|
// Variadic functions with ref-qualifiers
|
||||||
template<class Ret, class... Args>
|
template<class Ret, class... Args>
|
||||||
struct is_function<Ret(Args..., ...)&> : true_type
|
struct is_function<Ret(Args..., ...)&> : ctl::true_type
|
||||||
{};
|
{};
|
||||||
|
|
||||||
template<class Ret, class... Args>
|
template<class Ret, class... Args>
|
||||||
struct is_function<Ret(Args..., ...) const&> : true_type
|
struct is_function<Ret(Args..., ...) const&> : ctl::true_type
|
||||||
{};
|
{};
|
||||||
|
|
||||||
template<class Ret, class... Args>
|
template<class Ret, class... Args>
|
||||||
struct is_function<Ret(Args..., ...) volatile&> : true_type
|
struct is_function<Ret(Args..., ...) volatile&> : ctl::true_type
|
||||||
{};
|
{};
|
||||||
|
|
||||||
template<class Ret, class... Args>
|
template<class Ret, class... Args>
|
||||||
struct is_function<Ret(Args..., ...) const volatile&> : true_type
|
struct is_function<Ret(Args..., ...) const volatile&> : ctl::true_type
|
||||||
{};
|
{};
|
||||||
|
|
||||||
template<class Ret, class... Args>
|
template<class Ret, class... Args>
|
||||||
struct is_function<Ret(Args..., ...) &&> : true_type
|
struct is_function<Ret(Args..., ...) &&> : ctl::true_type
|
||||||
{};
|
{};
|
||||||
|
|
||||||
template<class Ret, class... Args>
|
template<class Ret, class... Args>
|
||||||
struct is_function<Ret(Args..., ...) const&&> : true_type
|
struct is_function<Ret(Args..., ...) const&&> : ctl::true_type
|
||||||
{};
|
{};
|
||||||
|
|
||||||
template<class Ret, class... Args>
|
template<class Ret, class... Args>
|
||||||
struct is_function<Ret(Args..., ...) volatile&&> : true_type
|
struct is_function<Ret(Args..., ...) volatile&&> : ctl::true_type
|
||||||
{};
|
{};
|
||||||
|
|
||||||
template<class Ret, class... Args>
|
template<class Ret, class... Args>
|
||||||
struct is_function<Ret(Args..., ...) const volatile&&> : true_type
|
struct is_function<Ret(Args..., ...) const volatile&&> : ctl::true_type
|
||||||
{};
|
{};
|
||||||
|
|
||||||
} // namespace ctl
|
} // namespace ctl
|
||||||
|
|
|
@ -7,67 +7,67 @@
|
||||||
namespace ctl {
|
namespace ctl {
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct is_integral : false_type
|
struct is_integral : ctl::false_type
|
||||||
{};
|
{};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct is_integral<bool> : true_type
|
struct is_integral<bool> : ctl::true_type
|
||||||
{};
|
{};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct is_integral<char> : true_type
|
struct is_integral<char> : ctl::true_type
|
||||||
{};
|
{};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct is_integral<signed char> : true_type
|
struct is_integral<signed char> : ctl::true_type
|
||||||
{};
|
{};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct is_integral<unsigned char> : true_type
|
struct is_integral<unsigned char> : ctl::true_type
|
||||||
{};
|
{};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct is_integral<short> : true_type
|
struct is_integral<short> : ctl::true_type
|
||||||
{};
|
{};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct is_integral<unsigned short> : true_type
|
struct is_integral<unsigned short> : ctl::true_type
|
||||||
{};
|
{};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct is_integral<int> : true_type
|
struct is_integral<int> : ctl::true_type
|
||||||
{};
|
{};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct is_integral<unsigned int> : true_type
|
struct is_integral<unsigned int> : ctl::true_type
|
||||||
{};
|
{};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct is_integral<long> : true_type
|
struct is_integral<long> : ctl::true_type
|
||||||
{};
|
{};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct is_integral<unsigned long> : true_type
|
struct is_integral<unsigned long> : ctl::true_type
|
||||||
{};
|
{};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct is_integral<long long> : true_type
|
struct is_integral<long long> : ctl::true_type
|
||||||
{};
|
{};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct is_integral<unsigned long long> : true_type
|
struct is_integral<unsigned long long> : ctl::true_type
|
||||||
{};
|
{};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct is_integral<char16_t> : true_type
|
struct is_integral<char16_t> : ctl::true_type
|
||||||
{};
|
{};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct is_integral<char32_t> : true_type
|
struct is_integral<char32_t> : ctl::true_type
|
||||||
{};
|
{};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct is_integral<wchar_t> : true_type
|
struct is_integral<wchar_t> : ctl::true_type
|
||||||
{};
|
{};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
namespace ctl {
|
namespace ctl {
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct is_polymorphic : public integral_constant<bool, __is_polymorphic(T)>
|
struct is_polymorphic : public ctl::integral_constant<bool, __is_polymorphic(T)>
|
||||||
{};
|
{};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
|
|
@ -8,7 +8,7 @@ namespace ctl {
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct is_standard_layout
|
struct is_standard_layout
|
||||||
: public integral_constant<bool, __is_standard_layout(T)>
|
: public ctl::integral_constant<bool, __is_standard_layout(T)>
|
||||||
{};
|
{};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
namespace ctl {
|
namespace ctl {
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct is_trivial : public integral_constant<bool, __is_trivial(T)>
|
struct is_trivial : public ctl::integral_constant<bool, __is_trivial(T)>
|
||||||
{};
|
{};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
namespace ctl {
|
namespace ctl {
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct is_union : public integral_constant<bool, __is_union(T)>
|
struct is_union : public ctl::integral_constant<bool, __is_union(T)>
|
||||||
{};
|
{};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
|
|
@ -20,7 +20,7 @@ class istream : public ios
|
||||||
istream& operator>>(long&);
|
istream& operator>>(long&);
|
||||||
istream& operator>>(double&);
|
istream& operator>>(double&);
|
||||||
istream& operator>>(bool&);
|
istream& operator>>(bool&);
|
||||||
istream& operator>>(string&);
|
istream& operator>>(ctl::string&);
|
||||||
istream& operator>>(istream& (*)(istream&));
|
istream& operator>>(istream& (*)(istream&));
|
||||||
|
|
||||||
int get();
|
int get();
|
||||||
|
|
|
@ -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)
|
: buffer_(str), read_pos_(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
string
|
ctl::string
|
||||||
istringstream::str() const
|
istringstream::str() const
|
||||||
{
|
{
|
||||||
return buffer_;
|
return buffer_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
istringstream::str(const string& s)
|
istringstream::str(const ctl::string& s)
|
||||||
{
|
{
|
||||||
buffer_ = s;
|
buffer_ = s;
|
||||||
read_pos_ = 0;
|
read_pos_ = 0;
|
||||||
|
@ -82,7 +82,7 @@ istringstream::operator>>(char* s)
|
||||||
}
|
}
|
||||||
|
|
||||||
istringstream&
|
istringstream&
|
||||||
istringstream::operator>>(string& s)
|
istringstream::operator>>(ctl::string& s)
|
||||||
{
|
{
|
||||||
if (!good())
|
if (!good())
|
||||||
return *this;
|
return *this;
|
||||||
|
|
|
@ -11,14 +11,14 @@ class istringstream : public ios_base
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
istringstream();
|
istringstream();
|
||||||
explicit istringstream(const string_view&);
|
explicit istringstream(const ctl::string_view&);
|
||||||
|
|
||||||
string str() const;
|
string str() const;
|
||||||
void str(const string&);
|
void str(const string&);
|
||||||
|
|
||||||
istringstream& operator>>(char&);
|
istringstream& operator>>(char&);
|
||||||
istringstream& operator>>(char*);
|
istringstream& operator>>(char*);
|
||||||
istringstream& operator>>(string&);
|
istringstream& operator>>(ctl::string&);
|
||||||
istringstream& operator>>(short&);
|
istringstream& operator>>(short&);
|
||||||
istringstream& operator>>(unsigned short&);
|
istringstream& operator>>(unsigned short&);
|
||||||
istringstream& operator>>(int&);
|
istringstream& operator>>(int&);
|
||||||
|
@ -29,7 +29,7 @@ class istringstream : public ios_base
|
||||||
istringstream& operator>>(double&);
|
istringstream& operator>>(double&);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
string buffer_;
|
ctl::string buffer_;
|
||||||
size_t read_pos_;
|
size_t read_pos_;
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
|
24
ctl/map.h
24
ctl/map.h
|
@ -152,12 +152,12 @@ class map
|
||||||
|
|
||||||
Value& operator[](const Key& key)
|
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)
|
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;
|
->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -244,7 +244,7 @@ class map
|
||||||
|
|
||||||
size_type erase(const Key& key)
|
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
|
void swap(map& other) noexcept
|
||||||
|
@ -259,47 +259,47 @@ class map
|
||||||
|
|
||||||
iterator find(const Key& key)
|
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
|
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
|
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)
|
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
|
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)
|
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
|
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<iterator, iterator> equal_range(const Key& key)
|
ctl::pair<iterator, iterator> equal_range(const Key& key)
|
||||||
{
|
{
|
||||||
return data_.equal_range(make_pair(key, Value()));
|
return data_.equal_range(ctl::make_pair(key, Value()));
|
||||||
}
|
}
|
||||||
|
|
||||||
ctl::pair<const_iterator, const_iterator> equal_range(const Key& key) const
|
ctl::pair<const_iterator, const_iterator> 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
|
key_compare key_comp() const
|
||||||
|
|
12
ctl/mutex.h
12
ctl/mutex.h
|
@ -11,17 +11,20 @@ class mutex
|
||||||
public:
|
public:
|
||||||
mutex()
|
mutex()
|
||||||
{
|
{
|
||||||
pthread_mutex_init(&m_, nullptr);
|
if (pthread_mutex_init(&m_, nullptr))
|
||||||
|
__builtin_trap();
|
||||||
}
|
}
|
||||||
|
|
||||||
~mutex()
|
~mutex()
|
||||||
{
|
{
|
||||||
pthread_mutex_destroy(&m_);
|
if (pthread_mutex_destroy(&m_))
|
||||||
|
__builtin_trap();
|
||||||
}
|
}
|
||||||
|
|
||||||
void lock()
|
void lock()
|
||||||
{
|
{
|
||||||
pthread_mutex_lock(&m_);
|
if (pthread_mutex_lock(&m_))
|
||||||
|
__builtin_trap();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool try_lock()
|
bool try_lock()
|
||||||
|
@ -31,7 +34,8 @@ class mutex
|
||||||
|
|
||||||
void unlock()
|
void unlock()
|
||||||
{
|
{
|
||||||
pthread_mutex_unlock(&m_);
|
if (pthread_mutex_unlock(&m_))
|
||||||
|
__builtin_trap();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete copy constructor and assignment operator
|
// Delete copy constructor and assignment operator
|
||||||
|
|
|
@ -20,7 +20,7 @@ class ostream : public ios
|
||||||
ostream& operator<<(int);
|
ostream& operator<<(int);
|
||||||
ostream& operator<<(long);
|
ostream& operator<<(long);
|
||||||
ostream& operator<<(double);
|
ostream& operator<<(double);
|
||||||
ostream& operator<<(const string_view&);
|
ostream& operator<<(const ctl::string_view&);
|
||||||
ostream& operator<<(bool);
|
ostream& operator<<(bool);
|
||||||
ostream& operator<<(ostream& (*)(ostream&));
|
ostream& operator<<(ostream& (*)(ostream&));
|
||||||
|
|
||||||
|
|
|
@ -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)
|
: buffer_(str), write_pos_(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
string
|
ctl::string
|
||||||
ostringstream::str() const
|
ostringstream::str() const
|
||||||
{
|
{
|
||||||
return buffer_;
|
return buffer_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ostringstream::str(const string& s)
|
ostringstream::str(const ctl::string& s)
|
||||||
{
|
{
|
||||||
buffer_ = s;
|
buffer_ = s;
|
||||||
write_pos_ = 0;
|
write_pos_ = 0;
|
||||||
|
@ -65,7 +65,7 @@ ostringstream::operator<<(char c)
|
||||||
}
|
}
|
||||||
|
|
||||||
ostringstream&
|
ostringstream&
|
||||||
ostringstream::operator<<(const string_view& s)
|
ostringstream::operator<<(const ctl::string_view& s)
|
||||||
{
|
{
|
||||||
if (good()) {
|
if (good()) {
|
||||||
if (write_pos_ + s.size() <= buffer_.size()) {
|
if (write_pos_ + s.size() <= buffer_.size()) {
|
||||||
|
@ -84,7 +84,7 @@ ostringstream::operator<<(int n)
|
||||||
{
|
{
|
||||||
char temp[12];
|
char temp[12];
|
||||||
if (good())
|
if (good())
|
||||||
*this << string_view(temp, FormatInt32(temp, n) - temp);
|
*this << ctl::string_view(temp, FormatInt32(temp, n) - temp);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@ ostringstream::operator<<(unsigned int n)
|
||||||
{
|
{
|
||||||
char temp[12];
|
char temp[12];
|
||||||
if (good())
|
if (good())
|
||||||
*this << string_view(temp, FormatUint32(temp, n) - temp);
|
*this << ctl::string_view(temp, FormatUint32(temp, n) - temp);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@ ostringstream::operator<<(long n)
|
||||||
{
|
{
|
||||||
char temp[21];
|
char temp[21];
|
||||||
if (good())
|
if (good())
|
||||||
*this << string_view(temp, FormatInt64(temp, n) - temp);
|
*this << ctl::string_view(temp, FormatInt64(temp, n) - temp);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,7 +111,7 @@ ostringstream::operator<<(unsigned long n)
|
||||||
{
|
{
|
||||||
char temp[21];
|
char temp[21];
|
||||||
if (good())
|
if (good())
|
||||||
*this << string_view(temp, FormatUint64(temp, n) - temp);
|
*this << ctl::string_view(temp, FormatUint64(temp, n) - temp);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,7 +121,7 @@ ostringstream::operator<<(float f)
|
||||||
if (good()) {
|
if (good()) {
|
||||||
char temp[32];
|
char temp[32];
|
||||||
int len = snprintf(temp, sizeof(temp), "%g", f);
|
int len = snprintf(temp, sizeof(temp), "%g", f);
|
||||||
*this << string_view(temp, len);
|
*this << ctl::string_view(temp, len);
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
@ -132,7 +132,7 @@ ostringstream::operator<<(double d)
|
||||||
if (good()) {
|
if (good()) {
|
||||||
char temp[32];
|
char temp[32];
|
||||||
int len = snprintf(temp, sizeof(temp), "%g", d);
|
int len = snprintf(temp, sizeof(temp), "%g", d);
|
||||||
*this << string_view(temp, len);
|
*this << ctl::string_view(temp, len);
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,14 +11,14 @@ class ostringstream : public ios_base
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ostringstream();
|
ostringstream();
|
||||||
explicit ostringstream(const string_view&);
|
explicit ostringstream(const ctl::string_view&);
|
||||||
|
|
||||||
string str() const;
|
ctl::string str() const;
|
||||||
void str(const string& s);
|
void str(const ctl::string& s);
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
ostringstream& operator<<(char);
|
ostringstream& operator<<(char);
|
||||||
ostringstream& operator<<(const string_view&);
|
ostringstream& operator<<(const ctl::string_view&);
|
||||||
ostringstream& operator<<(int);
|
ostringstream& operator<<(int);
|
||||||
ostringstream& operator<<(unsigned int);
|
ostringstream& operator<<(unsigned int);
|
||||||
ostringstream& operator<<(long);
|
ostringstream& operator<<(long);
|
||||||
|
@ -27,7 +27,7 @@ class ostringstream : public ios_base
|
||||||
ostringstream& operator<<(double);
|
ostringstream& operator<<(double);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
string buffer_;
|
ctl::string buffer_;
|
||||||
size_t write_pos_;
|
size_t write_pos_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
namespace ctl {
|
namespace ctl {
|
||||||
|
|
||||||
class out_of_range : public exception
|
class out_of_range : public ctl::exception
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
out_of_range() noexcept = default;
|
out_of_range() noexcept = default;
|
||||||
|
|
|
@ -13,11 +13,12 @@ class reverse_iterator
|
||||||
public:
|
public:
|
||||||
using iterator_type = Iterator;
|
using iterator_type = Iterator;
|
||||||
using iterator_category =
|
using iterator_category =
|
||||||
typename iterator_traits<Iterator>::iterator_category;
|
typename ctl::iterator_traits<Iterator>::iterator_category;
|
||||||
using value_type = typename iterator_traits<Iterator>::value_type;
|
using value_type = typename ctl::iterator_traits<Iterator>::value_type;
|
||||||
using difference_type = typename iterator_traits<Iterator>::difference_type;
|
using difference_type =
|
||||||
using pointer = typename iterator_traits<Iterator>::pointer;
|
typename ctl::iterator_traits<Iterator>::difference_type;
|
||||||
using reference = typename iterator_traits<Iterator>::reference;
|
using pointer = typename ctl::iterator_traits<Iterator>::pointer;
|
||||||
|
using reference = typename ctl::iterator_traits<Iterator>::reference;
|
||||||
|
|
||||||
constexpr reverse_iterator() : current()
|
constexpr reverse_iterator() : current()
|
||||||
{
|
{
|
||||||
|
|
29
ctl/set.h
29
ctl/set.h
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
namespace ctl {
|
namespace ctl {
|
||||||
|
|
||||||
template<typename Key, typename Compare = less<Key>>
|
template<typename Key, typename Compare = ctl::less<Key>>
|
||||||
class set
|
class set
|
||||||
{
|
{
|
||||||
struct rbtree
|
struct rbtree
|
||||||
|
@ -381,12 +381,12 @@ class set
|
||||||
size_ = 0;
|
size_ = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
pair<iterator, bool> insert(value_type&& value)
|
ctl::pair<iterator, bool> insert(value_type&& value)
|
||||||
{
|
{
|
||||||
return insert_node(new node_type(ctl::move(value)));
|
return insert_node(new node_type(ctl::move(value)));
|
||||||
}
|
}
|
||||||
|
|
||||||
pair<iterator, bool> insert(const value_type& value)
|
ctl::pair<iterator, bool> insert(const value_type& value)
|
||||||
{
|
{
|
||||||
return insert_node(new node_type(value));
|
return insert_node(new node_type(value));
|
||||||
}
|
}
|
||||||
|
@ -415,7 +415,7 @@ class set
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class... Args>
|
template<class... Args>
|
||||||
pair<iterator, bool> emplace(Args&&... args)
|
ctl::pair<iterator, bool> emplace(Args&&... args)
|
||||||
{
|
{
|
||||||
value_type value(ctl::forward<Args>(args)...);
|
value_type value(ctl::forward<Args>(args)...);
|
||||||
return insert(ctl::move(value));
|
return insert(ctl::move(value));
|
||||||
|
@ -451,12 +451,13 @@ class set
|
||||||
ctl::swap(size_, other.size_);
|
ctl::swap(size_, other.size_);
|
||||||
}
|
}
|
||||||
|
|
||||||
pair<iterator, iterator> equal_range(const key_type& key)
|
ctl::pair<iterator, iterator> equal_range(const key_type& key)
|
||||||
{
|
{
|
||||||
return { iterator(get_floor(key)), iterator(get_ceiling(key)) };
|
return { iterator(get_floor(key)), iterator(get_ceiling(key)) };
|
||||||
}
|
}
|
||||||
|
|
||||||
pair<const_iterator, const_iterator> equal_range(const key_type& key) const
|
ctl::pair<const_iterator, const_iterator> equal_range(
|
||||||
|
const key_type& key) const
|
||||||
{
|
{
|
||||||
return { const_iterator(get_floor(key)),
|
return { const_iterator(get_floor(key)),
|
||||||
const_iterator(get_ceiling(key)) };
|
const_iterator(get_ceiling(key)) };
|
||||||
|
@ -613,7 +614,7 @@ class set
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
pair<iterator, bool> insert_node(node_type* node)
|
ctl::pair<iterator, bool> insert_node(node_type* node)
|
||||||
{
|
{
|
||||||
if (root_ == nullptr) {
|
if (root_ == nullptr) {
|
||||||
root_ = node;
|
root_ = node;
|
||||||
|
@ -878,7 +879,7 @@ class set
|
||||||
Compare comp_;
|
Compare comp_;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<class Key, typename Compare = less<Key>>
|
template<class Key, typename Compare = ctl::less<Key>>
|
||||||
bool
|
bool
|
||||||
operator==(const set<Key, Compare>& lhs, const set<Key, Compare>& rhs)
|
operator==(const set<Key, Compare>& lhs, const set<Key, Compare>& rhs)
|
||||||
{
|
{
|
||||||
|
@ -893,7 +894,7 @@ operator==(const set<Key, Compare>& lhs, const set<Key, Compare>& rhs)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class Key, typename Compare = less<Key>>
|
template<class Key, typename Compare = ctl::less<Key>>
|
||||||
bool
|
bool
|
||||||
operator<(const set<Key, Compare>& lhs, const set<Key, Compare>& rhs)
|
operator<(const set<Key, Compare>& lhs, const set<Key, Compare>& rhs)
|
||||||
{
|
{
|
||||||
|
@ -908,35 +909,35 @@ operator<(const set<Key, Compare>& lhs, const set<Key, Compare>& rhs)
|
||||||
return i == lhs.end() && j != rhs.end();
|
return i == lhs.end() && j != rhs.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class Key, typename Compare = less<Key>>
|
template<class Key, typename Compare = ctl::less<Key>>
|
||||||
bool
|
bool
|
||||||
operator!=(const set<Key, Compare>& lhs, const set<Key, Compare>& rhs)
|
operator!=(const set<Key, Compare>& lhs, const set<Key, Compare>& rhs)
|
||||||
{
|
{
|
||||||
return !(lhs == rhs);
|
return !(lhs == rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class Key, typename Compare = less<Key>>
|
template<class Key, typename Compare = ctl::less<Key>>
|
||||||
bool
|
bool
|
||||||
operator<=(const set<Key, Compare>& lhs, const set<Key, Compare>& rhs)
|
operator<=(const set<Key, Compare>& lhs, const set<Key, Compare>& rhs)
|
||||||
{
|
{
|
||||||
return !(rhs < lhs);
|
return !(rhs < lhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class Key, typename Compare = less<Key>>
|
template<class Key, typename Compare = ctl::less<Key>>
|
||||||
bool
|
bool
|
||||||
operator>(const set<Key, Compare>& lhs, const set<Key, Compare>& rhs)
|
operator>(const set<Key, Compare>& lhs, const set<Key, Compare>& rhs)
|
||||||
{
|
{
|
||||||
return rhs < lhs;
|
return rhs < lhs;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class Key, typename Compare = less<Key>>
|
template<class Key, typename Compare = ctl::less<Key>>
|
||||||
bool
|
bool
|
||||||
operator>=(const set<Key, Compare>& lhs, const set<Key, Compare>& rhs)
|
operator>=(const set<Key, Compare>& lhs, const set<Key, Compare>& rhs)
|
||||||
{
|
{
|
||||||
return !(lhs < rhs);
|
return !(lhs < rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class Key, typename Compare = less<Key>>
|
template<class Key, typename Compare = ctl::less<Key>>
|
||||||
void
|
void
|
||||||
swap(set<Key, Compare>& lhs, set<Key, Compare>& rhs) noexcept;
|
swap(set<Key, Compare>& lhs, set<Key, Compare>& rhs) noexcept;
|
||||||
|
|
||||||
|
|
50
ctl/string.h
50
ctl/string.h
|
@ -9,7 +9,7 @@ namespace ctl {
|
||||||
|
|
||||||
class string;
|
class string;
|
||||||
|
|
||||||
string strcat(string_view, string_view) noexcept __wur;
|
ctl::string strcat(ctl::string_view, ctl::string_view) noexcept __wur;
|
||||||
|
|
||||||
namespace __ {
|
namespace __ {
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ class string
|
||||||
*(((size_t*)blob) + 2) = __::sso_max << (sizeof(size_t) - 1) * 8;
|
*(((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) {
|
if (s.n <= __::sso_max) {
|
||||||
__builtin_memcpy(blob, s.p, s.n);
|
__builtin_memcpy(blob, s.p, s.n);
|
||||||
|
@ -89,7 +89,7 @@ class string
|
||||||
}
|
}
|
||||||
|
|
||||||
string(const char* const p) noexcept
|
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(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(char, size_t) noexcept;
|
||||||
void append(unsigned long) noexcept;
|
void append(unsigned long) noexcept;
|
||||||
void append(const void*, size_t) 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& erase(size_t = 0, size_t = npos) noexcept;
|
||||||
string substr(size_t = 0, size_t = npos) const noexcept;
|
string substr(size_t = 0, size_t = npos) const noexcept;
|
||||||
string& replace(size_t, size_t, string_view) noexcept;
|
string& replace(size_t, size_t, ctl::string_view) noexcept;
|
||||||
bool operator==(string_view) const noexcept;
|
bool operator==(ctl::string_view) const noexcept;
|
||||||
bool operator!=(string_view) const noexcept;
|
bool operator!=(ctl::string_view) const noexcept;
|
||||||
bool contains(string_view) const noexcept;
|
bool contains(ctl::string_view) const noexcept;
|
||||||
bool ends_with(string_view) const noexcept;
|
bool ends_with(ctl::string_view) const noexcept;
|
||||||
bool starts_with(string_view) const noexcept;
|
bool starts_with(ctl::string_view) const noexcept;
|
||||||
size_t find(char, size_t = 0) 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
|
void swap(string& s) noexcept
|
||||||
{
|
{
|
||||||
|
@ -302,14 +302,14 @@ class string
|
||||||
append(ch);
|
append(ch);
|
||||||
}
|
}
|
||||||
|
|
||||||
void append(const string_view s) noexcept
|
void append(const ctl::string_view s) noexcept
|
||||||
{
|
{
|
||||||
append(s.p, s.n);
|
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
|
string& operator=(const char* s) noexcept
|
||||||
|
@ -319,7 +319,7 @@ class string
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
string& operator=(const string_view s) noexcept
|
string& operator=(const ctl::string_view s) noexcept
|
||||||
{
|
{
|
||||||
clear();
|
clear();
|
||||||
append(s);
|
append(s);
|
||||||
|
@ -332,38 +332,38 @@ class string
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
string& operator+=(const string_view s) noexcept
|
string& operator+=(const ctl::string_view s) noexcept
|
||||||
{
|
{
|
||||||
append(s);
|
append(s);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
string operator+(const string_view s) const noexcept
|
string operator+(const ctl::string_view s) const noexcept
|
||||||
{
|
{
|
||||||
return strcat(*this, s);
|
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);
|
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;
|
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;
|
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;
|
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;
|
return compare(s) >= 0;
|
||||||
}
|
}
|
||||||
|
@ -371,7 +371,7 @@ class string
|
||||||
private:
|
private:
|
||||||
void destroy_big() noexcept;
|
void destroy_big() noexcept;
|
||||||
void init_big(const string&) 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;
|
void init_big(size_t, char) noexcept;
|
||||||
|
|
||||||
__attribute__((__always_inline__)) bool isbig() const noexcept
|
__attribute__((__always_inline__)) bool isbig() const noexcept
|
||||||
|
@ -395,7 +395,7 @@ class string
|
||||||
__b.c = c2 | ~__::big_mask;
|
__b.c = c2 | ~__::big_mask;
|
||||||
}
|
}
|
||||||
|
|
||||||
friend string strcat(string_view, string_view) noexcept;
|
friend string strcat(ctl::string_view, ctl::string_view) noexcept;
|
||||||
|
|
||||||
union
|
union
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue