Changeset 6175b78 in mainline


Ignore:
Timestamp:
2018-07-05T21:41:23Z (6 years ago)
Author:
Dzejrou <dzejrou@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
73e3791
Parents:
9c9ee5d
git-author:
Dzejrou <dzejrou@…> (2018-05-12 21:01:29)
git-committer:
Dzejrou <dzejrou@…> (2018-07-05 21:41:23)
Message:

cpp: added most of the remaining type traits

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/cpp/include/impl/type_traits.hpp

    r9c9ee5d r6175b78  
    564564
    565565    template<class T>
    566     struct is_standard_layout;
     566    struct is_standard_layout: aux::value_is<bool, __is_standard_layout(T)>
     567    { /* DUMMY BODY */ };
    567568
    568569    template<class T>
     
    669670
    670671    template<class T>
    671     struct is_default_constructible;
    672 
    673     template<class T>
    674     struct is_copy_constructible;
    675 
    676     template<class T>
    677     struct is_move_constructible;
     672    struct is_default_constructible
     673        : is_constructible<T>
     674    { /* DUMMY BODY */ };
     675
     676    template<class T>
     677    struct is_copy_constructible
     678        : is_constructible<T, add_lvalue_reference<const T>>
     679    { /* DUMMY BODY */ };
     680
     681    template<class T>
     682    struct is_move_constructible
     683        : is_constructible<T, add_rvalue_reference<T>>
     684    { /* DUMMY BODY */ };
     685
     686    template<class T, class U, class = void>
     687    struct is_assignable: false_type
     688    { /* DUMMY BODY */ };
    678689
    679690    template<class T, class U>
    680     struct is_assignable;
    681 
    682     template<class T>
    683     struct is_copy_assignable;
    684 
    685     template<class T>
    686     struct is_move_assignable;
    687 
    688     template<class T>
    689     struct is_destructible;
     691    struct is_assignable<T, U, void_t<decltype(declval<T>() = declval<U>())>>
     692        : true_type
     693    { /* DUMMY BODY */ };
     694
     695    template<class T>
     696    struct is_copy_assignable
     697        : is_assignable<add_lvalue_reference_t<T>, add_lvalue_reference_t<const T>>
     698    { /* DUMMY BODY */ };
     699
     700    template<class T>
     701    struct is_move_assignable
     702        : is_assignable<add_lvalue_reference_t<T>, add_rvalue_reference_t<T>>
     703    { /* DUMMY BODY */ };
     704
     705    template<class, class = void>
     706    struct is_destructible: false_type
     707    { /* DUMMY BODY */ };
     708
     709    template<class T>
     710    struct is_destructible<T, void_t<decltype(declval<T&>().~T())>>
     711        : true_type
     712    { /* DUMMY BODY */ };
    690713
    691714    template<class T, class... Args>
     
    697720
    698721    template<class T>
    699     struct is_trivially_default_constructible;
     722    struct is_trivially_default_constructible
     723        : is_trivially_constructible<T>
     724    { /* DUMMY BODY */ };
    700725
    701726    template<class T>
     
    707732
    708733    template<class T>
    709     struct is_trivially_move_constructible;
     734    struct is_trivially_move_constructible
     735        : is_trivially_constructible<T, add_rvalue_reference_t<T>>
     736    { /* DUMMY BODY */ };
    710737
    711738    template<class T, class U>
    712     struct is_trivially_assignable: aux::value_is<bool, __has_trivial_assign(T)>
     739    struct is_trivially_assignable: aux::value_is<bool, __has_trivial_assign(T) && is_assignable<T, U>::value>
    713740    { /* DUMMY BODY */ };
    714741
     
    717744
    718745    template<class T>
    719     struct is_trivially_copy_assignable;
    720 
    721     template<class T>
    722     struct is_trivially_move_assignable;
     746    struct is_trivially_copy_assignable
     747        : is_trivially_assignable<add_lvalue_reference_t<T>, add_lvalue_reference_t<const T>>
     748    { /* DUMMY BODY */ };
     749
     750    template<class T>
     751    struct is_trivially_move_assignable
     752        : is_trivially_assignable<add_lvalue_reference_t<T>, add_rvalue_reference_t<T>>
     753    { /* DUMMY BODY */ };
    723754
    724755    template<class T>
     
    737768
    738769    template<class T>
    739     struct is_nothrow_default_constructible;
     770    struct is_nothrow_default_constructible
     771        : is_nothrow_constructible<T>
     772    { /* DUMMY BODY */ };
    740773
    741774    template<class T>
     
    747780
    748781    template<class T>
    749     struct is_nothrow_move_constructible;
     782    struct is_nothrow_move_constructible
     783        : is_nothrow_constructible<add_lvalue_reference_t<T>, add_rvalue_reference_t<T>>
     784    { /* DUMMY BODY */ };
    750785
    751786    template<class T, class U>
     
    757792
    758793    template<class T>
    759     struct is_nothrow_copy_assignable;
    760 
    761     template<class T>
    762     struct is_nothrow_move_assignable;
    763 
    764     template<class T>
    765     struct is_nothrow_destructible;
     794    struct is_nothrow_copy_assignable
     795        : is_nothrow_assignable<add_lvalue_reference_t<T>, add_lvalue_reference_t<const T>>
     796    { /* DUMMY BODY */ };
     797
     798    template<class T>
     799    struct is_nothrow_move_assignable
     800        : is_nothrow_assignable<add_lvalue_reference_t<T>, add_rvalue_reference_t<T>>
     801    { /* DUMMY BODY */ };
     802
     803    template<class, class = void>
     804    struct is_nothrow_destructible: false_type
     805    { /* DUMMY BODY */ };
     806
     807    template<class T>
     808    struct is_nothrow_destructible<T, void_t<decltype(declval<T&>().~T())>>
     809        : aux::value_is<bool, noexcept(declval<T&>().~T())>
     810    { /* DUMMY BODY */ };
    766811
    767812    template<class T>
     
    777822
    778823    template<class T>
    779     struct alignment_of;
     824    struct alignment_of: aux::value_is<std::size_t, alignof(T)>
     825    { /* DUMMY BODY */ };
    780826
    781827    template<class>
     
    794840    inline constexpr size_t rank_v = rank<T>::value;
    795841
    796     template<class T, unsigned I = 0>
    797     struct extent;
     842    template<class T, unsigned I = 0U>
     843    struct extent: aux::value_is<size_t, 0U>
     844    { /* DUMMY BODY */ };
     845
     846    template<class T>
     847    struct extent<T[], 0U>: aux::value_is<size_t, 0U>
     848    { /* DUMMY BODY */ };
     849
     850    template<class T, unsigned I>
     851    struct extent<T[], I>: extent<T, I - 1>
     852    { /* DUMMY BODY */ };
     853
     854    template<class T, size_t N>
     855    struct extent<T[N], 0U>: aux::value_is<size_t, 0U>
     856    { /* DUMMY BODY */ };
     857
     858    template<class T, unsigned I, size_t N>
     859    struct extent<T[N], I>: extent<T, I - 1>
     860    { /* DUMMY BODY */ };
    798861
    799862    /**
     
    926989
    927990    template<class T>
    928     struct remove_all_extents;
     991    struct remove_all_extents: aux::type_is<T>
     992    { /* DUMMY BODY */ };
     993
     994    template<class T>
     995    struct remove_all_extents<T[]>: remove_all_extents<T>
     996    { /* DUMMY BODY */ };
     997
     998    template<class T, size_t N>
     999    struct remove_all_extents<T[N]>: remove_all_extents<T>
     1000    { /* DUMMY BODY */ };
    9291001
    9301002    template<class T>
     
    9581030    { /* DUMMY BODY */ };
    9591031
    960     template<class T>
    961     struct add_pointer;
     1032    namespace aux
     1033    {
     1034        template<class T>
     1035        struct add_pointer_to_function: type_is<T>
     1036        { /* DUMMY BODY */ };
     1037
     1038        template<class T, class... Args>
     1039        struct add_pointer_to_function<T(Args...)>
     1040            : type_is<T(*)(Args...)>
     1041        { /* DUMMY BODY */ };
     1042
     1043        template<class T, bool = false>
     1044        struct add_pointer_cond: aux::type_is<remove_reference_t<T>*>
     1045        { /* DUMMY BODY */ };
     1046
     1047        template<class T>
     1048        struct add_pointer_cond<T, true>
     1049            : aux::add_pointer_to_function<T>
     1050        { /* DUMMY BODY */ };
     1051    }
     1052
     1053    template<class T>
     1054    struct add_pointer: aux::add_pointer_cond<T, is_function_v<T>>
     1055    { /* DUMMY BODY */ };
    9621056
    9631057    template<class T>
     
    9701064     * 20.10.7.6, other transformations:
    9711065     */
     1066
     1067    namespace aux
     1068    {
     1069        template<size_t Len, size_t Align>
     1070        struct aligned_t
     1071        {
     1072            alignas(Align) uint8_t storage[Len];
     1073        };
     1074
     1075        template<class T>
     1076        constexpr T max_of_cont(T cont)
     1077        {
     1078            if (cont.size() == 0U)
     1079                return T{};
     1080
     1081            auto it = cont.begin();
     1082            auto res = *it;
     1083
     1084            while (++it != cont.end())
     1085            {
     1086                if (*it > res)
     1087                    res = *it;
     1088            }
     1089
     1090            return res;
     1091        }
     1092    }
    9721093
    9731094    // TODO: consult standard on the default value of align
    9741095    template<std::size_t Len, std::size_t Align = 0>
    975     struct aligned_storage;
     1096    struct aligned_storage: aux::type_is<aux::aligned_t<Len, Align>>
     1097    { /* DUMMY BODY */ };
    9761098
    9771099    template<std::size_t Len, class... Types>
    978     struct aligned_union;
     1100    struct aligned_union: aux::type_is<
     1101        aux::aligned_t<
     1102            aux::max_of_cont({Len, alignof(Types)...}),
     1103            aux::max_of_cont({alignof(Types)...})
     1104        >
     1105    >
     1106    { /* DUMMY BODY */ };
    9791107
    9801108        // TODO: this is very basic implementation for chrono, fix!
    981     template<class T>
    982     struct decay: aux::type_is<remove_cv_t<remove_reference_t<T>>>
    983         { /* DUMMY BODY */ };
     1109    /* template<class T> */
     1110    /* struct decay: aux::type_is<remove_cv_t<remove_reference_t<T>>> */
     1111        /* { /1* DUMMY BODY *1/ }; */
     1112
     1113    template<bool, class, class>
     1114    struct conditional;
     1115
     1116    template<class T>
     1117    struct decay: aux::type_is<
     1118        typename conditional<
     1119            is_array_v<remove_reference_t<T>>,
     1120            remove_extent_t<remove_reference_t<T>>*,
     1121            typename conditional<
     1122                is_function_v<remove_reference_t<T>>,
     1123                add_pointer_t<remove_reference_t<T>>,
     1124                remove_cv_t<remove_reference_t<T>>
     1125            >::type
     1126        >::type
     1127    >
     1128    { /* DUMMY BODY */ };
    9841129
    9851130        template<class T>
Note: See TracChangeset for help on using the changeset viewer.