Skip to content

Commit

Permalink
Make CTL definitions less ambiguous
Browse files Browse the repository at this point in the history
  • Loading branch information
jart committed Jul 1, 2024
1 parent 239f8ce commit acbabed
Show file tree
Hide file tree
Showing 30 changed files with 176 additions and 173 deletions.
27 changes: 10 additions & 17 deletions ctl/allocator_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,52 +18,45 @@ 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<typename T>
using rebind_alloc = typename Alloc::template rebind<T>::other;

template<typename T>
using rebind_traits = allocator_traits<rebind_alloc<T>>;

__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<typename T, typename... Args>
__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&&>(args)...);
}

template<typename T>
__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;
}
Expand Down
2 changes: 1 addition & 1 deletion ctl/bad_alloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace ctl {

class bad_alloc : public exception
class bad_alloc : public ctl::exception
{
public:
bad_alloc() noexcept = default;
Expand Down
15 changes: 8 additions & 7 deletions ctl/decay.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@ template<typename T>
struct decay
{
private:
typedef typename remove_reference<T>::type U;
typedef typename ctl::remove_reference<T>::type U;

public:
typedef typename conditional<
is_array<U>::value,
typename remove_extent<U>::type*,
typename conditional<is_function<U>::value,
typename add_pointer<U>::type,
typename remove_cv<U>::type>::type>::type type;
typedef typename ctl::conditional<
ctl::is_array<U>::value,
typename ctl::remove_extent<U>::type*,
typename ctl::conditional<ctl::is_function<U>::value,
typename ctl::add_pointer<U>::type,
typename ctl::remove_cv<U>::type>::type>::type
type;
};

template<typename T>
Expand Down
12 changes: 7 additions & 5 deletions ctl/distance.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,30 @@
namespace ctl {

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)
{
typename iterator_traits<InputIter>::difference_type res(0);
typename ctl::iterator_traits<InputIter>::difference_type res(0);
for (; first != last; ++first)
++res;
return res;
}

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)
{
return last - first;
}

template<class InputIter>
constexpr typename iterator_traits<InputIter>::difference_type
constexpr typename ctl::iterator_traits<InputIter>::difference_type
distance(InputIter first, InputIter last)
{
return distance_impl(
first, last, typename iterator_traits<InputIter>::iterator_category());
first,
last,
typename ctl::iterator_traits<InputIter>::iterator_category());
}

} // namespace ctl
Expand Down
2 changes: 1 addition & 1 deletion ctl/is_abstract.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace ctl {

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>
Expand Down
6 changes: 3 additions & 3 deletions ctl/is_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
namespace ctl {

template<typename T>
struct is_array : false_type
struct is_array : ctl::false_type
{};

template<typename T, size_t N>
struct is_array<T[N]> : true_type
struct is_array<T[N]> : ctl::true_type
{};

template<typename T>
struct is_array<T[]> : true_type
struct is_array<T[]> : ctl::true_type
{};

template<typename T>
Expand Down
3 changes: 2 additions & 1 deletion ctl/is_base_of.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
namespace ctl {

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>
Expand Down
2 changes: 1 addition & 1 deletion ctl/is_class.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace ctl {

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>
Expand Down
2 changes: 1 addition & 1 deletion ctl/is_constructible.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace ctl {

template<class _Tp, class... _Args>
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>
Expand Down
8 changes: 4 additions & 4 deletions ctl/is_convertible.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ declval() noexcept;
namespace detail {

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>
Expand All @@ -27,15 +27,15 @@ struct is_convertible_impl<From,

// Handle void types separately
template<>
struct is_convertible_impl<void, void> : true_type
struct is_convertible_impl<void, void> : ctl::true_type
{};

template<typename To>
struct is_convertible_impl<void, To> : false_type
struct is_convertible_impl<void, To> : ctl::false_type
{};

template<typename From>
struct is_convertible_impl<From, void> : false_type
struct is_convertible_impl<From, void> : ctl::false_type
{};

} // namespace detail
Expand Down
2 changes: 1 addition & 1 deletion ctl/is_empty.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace ctl {

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>
Expand Down
2 changes: 1 addition & 1 deletion ctl/is_enum.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace ctl {

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>
Expand Down
50 changes: 25 additions & 25 deletions ctl/is_function.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,111 +8,111 @@ namespace ctl {

// Primary template
template<class>
struct is_function : false_type
struct is_function : ctl::false_type
{};

// Specializations for various function types

// Regular functions
template<class Ret, class... Args>
struct is_function<Ret(Args...)> : true_type
struct is_function<Ret(Args...)> : ctl::true_type
{};

// Functions with cv-qualifiers
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>
struct is_function<Ret(Args...) volatile> : true_type
struct is_function<Ret(Args...) volatile> : ctl::true_type
{};

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
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>
struct is_function<Ret(Args...) const&> : true_type
struct is_function<Ret(Args...) const&> : ctl::true_type
{};

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>
struct is_function<Ret(Args...) const volatile&> : true_type
struct is_function<Ret(Args...) const volatile&> : ctl::true_type
{};

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>
struct is_function<Ret(Args...) const&&> : true_type
struct is_function<Ret(Args...) const&&> : ctl::true_type
{};

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>
struct is_function<Ret(Args...) const volatile&&> : true_type
struct is_function<Ret(Args...) const volatile&&> : ctl::true_type
{};

// Variadic functions
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
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>
struct is_function<Ret(Args..., ...) volatile> : true_type
struct is_function<Ret(Args..., ...) volatile> : ctl::true_type
{};

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
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>
struct is_function<Ret(Args..., ...) const&> : true_type
struct is_function<Ret(Args..., ...) const&> : ctl::true_type
{};

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>
struct is_function<Ret(Args..., ...) const volatile&> : true_type
struct is_function<Ret(Args..., ...) const volatile&> : ctl::true_type
{};

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>
struct is_function<Ret(Args..., ...) const&&> : true_type
struct is_function<Ret(Args..., ...) const&&> : ctl::true_type
{};

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>
struct is_function<Ret(Args..., ...) const volatile&&> : true_type
struct is_function<Ret(Args..., ...) const volatile&&> : ctl::true_type
{};

} // namespace ctl
Expand Down
Loading

0 comments on commit acbabed

Please sign in to comment.