Home | History | Annotate | Download | only in meta.type.synop
      1 //===----------------------------------------------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is dual licensed under the MIT and the University of Illinois Open
      6 // Source Licenses. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 // UNSUPPORTED: c++98, c++03, c++11
     11 // <experimental/type_traits>
     12 
     13 #include <experimental/type_traits>
     14 
     15 namespace ex = std::experimental;
     16 
     17 struct non_literal_type { non_literal_type() {} };
     18 struct empty_type {};
     19 
     20 struct polymorphic_type
     21 {
     22     virtual void foo() {}
     23 };
     24 
     25 struct abstract_type
     26 {
     27     virtual void foo() = 0;
     28 };
     29 
     30 struct final_type final {};
     31 
     32 struct virtual_dtor_type
     33 {
     34     virtual ~virtual_dtor_type() {}
     35 };
     36 
     37 void type_properties_test()
     38 {
     39     {
     40         typedef const int T;
     41         static_assert(ex::is_const_v<T>, "");
     42         static_assert(std::is_same<decltype(ex::is_const_v<T>), const bool>::value, "");
     43         static_assert(ex::is_const_v<T> == std::is_const<T>::value, "");
     44     }
     45     {
     46         typedef int T;
     47         static_assert(!ex::is_const_v<T>, "");
     48         static_assert(ex::is_const_v<T> == std::is_const<T>::value, "");
     49     }
     50     {
     51         typedef volatile int T;
     52         static_assert(ex::is_volatile_v<T>, "");
     53         static_assert(std::is_same<decltype(ex::is_volatile_v<T>), const bool>::value, "");
     54         static_assert(ex::is_volatile_v<T> == std::is_volatile<T>::value, "");
     55     }
     56     {
     57         typedef int T;
     58         static_assert(!ex::is_volatile_v<T>, "");
     59         static_assert(ex::is_volatile_v<T> == std::is_volatile<T>::value, "");
     60     }
     61     {
     62         typedef int T;
     63         static_assert(ex::is_trivial_v<T>, "");
     64         static_assert(std::is_same<decltype(ex::is_trivial_v<T>), const bool>::value, "");
     65         static_assert(ex::is_trivial_v<T> == std::is_trivial<T>::value, "");
     66     }
     67     {
     68         typedef int & T;
     69         static_assert(!ex::is_trivial_v<T>, "");
     70         static_assert(ex::is_trivial_v<T> == std::is_trivial<T>::value, "");
     71     }
     72     {
     73         typedef int T;
     74         static_assert(ex::is_trivially_copyable_v<T>, "");
     75         static_assert(std::is_same<decltype(ex::is_trivially_copyable_v<T>), const bool>::value, "");
     76         static_assert(ex::is_trivially_copyable_v<T> == std::is_trivially_copyable<T>::value, "");
     77     }
     78     {
     79         typedef int & T;
     80         static_assert(!ex::is_trivially_copyable_v<T>, "");
     81         static_assert(ex::is_trivially_copyable_v<T> == std::is_trivially_copyable<T>::value, "");
     82     }
     83     {
     84         typedef int T;
     85         static_assert(ex::is_standard_layout_v<T>, "");
     86         static_assert(std::is_same<decltype(ex::is_standard_layout_v<T>), const bool>::value, "");
     87         static_assert(ex::is_standard_layout_v<T> == std::is_standard_layout<T>::value, "");
     88     }
     89     {
     90         typedef int & T;
     91         static_assert(!ex::is_standard_layout_v<T>, "");
     92         static_assert(ex::is_standard_layout_v<T> == std::is_standard_layout<T>::value, "");
     93     }
     94     {
     95         typedef int T;
     96         static_assert(ex::is_pod_v<T>, "");
     97         static_assert(std::is_same<decltype(ex::is_pod_v<T>), const bool>::value, "");
     98         static_assert(ex::is_pod_v<T> == std::is_pod<T>::value, "");
     99     }
    100     {
    101         typedef int & T;
    102         static_assert(!ex::is_pod_v<T>, "");
    103         static_assert(ex::is_pod_v<T> == std::is_pod<T>::value, "");
    104     }
    105     {
    106         typedef int T;
    107         static_assert(ex::is_literal_type_v<T>, "");
    108         static_assert(std::is_same<decltype(ex::is_literal_type_v<T>), const bool>::value, "");
    109         static_assert(ex::is_literal_type_v<T> == std::is_literal_type<T>::value, "");
    110     }
    111     {
    112         typedef non_literal_type T;
    113         static_assert(!ex::is_literal_type_v<T>, "");
    114         static_assert(ex::is_literal_type_v<T> == std::is_literal_type<T>::value, "");
    115     }
    116     {
    117         typedef empty_type T;
    118         static_assert(ex::is_empty_v<T>, "");
    119         static_assert(std::is_same<decltype(ex::is_empty_v<T>), const bool>::value, "");
    120         static_assert(ex::is_empty_v<T> == std::is_empty<T>::value, "");
    121     }
    122     {
    123         typedef int T;
    124         static_assert(!ex::is_empty_v<T>, "");
    125         static_assert(ex::is_empty_v<T> == std::is_empty<T>::value, "");
    126     }
    127     {
    128         typedef polymorphic_type T;
    129         static_assert(ex::is_polymorphic_v<T>, "");
    130         static_assert(std::is_same<decltype(ex::is_polymorphic_v<T>), const bool>::value, "");
    131         static_assert(ex::is_polymorphic_v<T> == std::is_polymorphic<T>::value, "");
    132     }
    133     {
    134         typedef int T;
    135         static_assert(!ex::is_polymorphic_v<T>, "");
    136         static_assert(ex::is_polymorphic_v<T> == std::is_polymorphic<T>::value, "");
    137     }
    138     {
    139         typedef abstract_type T;
    140         static_assert(ex::is_abstract_v<T>, "");
    141         static_assert(std::is_same<decltype(ex::is_abstract_v<T>), const bool>::value, "");
    142         static_assert(ex::is_abstract_v<T> == std::is_abstract<T>::value, "");
    143     }
    144     {
    145         typedef int T;
    146         static_assert(!ex::is_abstract_v<T>, "");
    147         static_assert(ex::is_abstract_v<T> == std::is_abstract<T>::value, "");
    148     }
    149     {
    150         typedef final_type T;
    151         static_assert(ex::is_final_v<T>, "");
    152         static_assert(std::is_same<decltype(ex::is_final_v<T>), const bool>::value, "");
    153         static_assert(ex::is_final_v<T> == std::is_final<T>::value, "");
    154     }
    155     {
    156         typedef int T;
    157         static_assert(!ex::is_final_v<T>, "");
    158         static_assert(ex::is_final_v<T> == std::is_final<T>::value, "");
    159     }
    160     {
    161         typedef int T;
    162         static_assert(ex::is_signed_v<T>, "");
    163         static_assert(std::is_same<decltype(ex::is_signed_v<T>), const bool>::value, "");
    164         static_assert(ex::is_signed_v<T> == std::is_signed<T>::value, "");
    165     }
    166     {
    167         typedef unsigned T;
    168         static_assert(!ex::is_signed_v<T>, "");
    169         static_assert(ex::is_signed_v<T> == std::is_signed<T>::value, "");
    170     }
    171     {
    172         typedef unsigned T;
    173         static_assert(ex::is_unsigned_v<T>, "");
    174         static_assert(std::is_same<decltype(ex::is_unsigned_v<T>), const bool>::value, "");
    175         static_assert(ex::is_unsigned_v<T> == std::is_unsigned<T>::value, "");
    176     }
    177     {
    178         typedef int T;
    179         static_assert(!ex::is_unsigned_v<T>, "");
    180         static_assert(ex::is_unsigned_v<T> == std::is_unsigned<T>::value, "");
    181     }
    182 }
    183 
    184 void is_constructible_and_assignable_test()
    185 {
    186     {
    187         typedef int T;
    188         static_assert(ex::is_constructible_v<T, int>, "");
    189         static_assert(std::is_same<decltype(ex::is_constructible_v<T, int>), const bool>::value, "");
    190         static_assert(ex::is_constructible_v<T, int> == std::is_constructible<T, int>::value, "");
    191     }
    192     {
    193         typedef void T;
    194         static_assert(!ex::is_constructible_v<T, int>, "");
    195         static_assert(ex::is_constructible_v<T, int> == std::is_constructible<T, int>::value, "");
    196     }
    197     {
    198         typedef int T;
    199         static_assert(ex::is_default_constructible_v<T>, "");
    200         static_assert(std::is_same<decltype(ex::is_default_constructible_v<T>), const bool>::value, "");
    201         static_assert(ex::is_default_constructible_v<T> == std::is_default_constructible<T>::value, "");
    202     }
    203     {
    204         typedef int & T;
    205         static_assert(!ex::is_default_constructible_v<T>, "");
    206         static_assert(ex::is_default_constructible_v<T> == std::is_default_constructible<T>::value, "");
    207     }
    208     {
    209         typedef int T;
    210         static_assert(ex::is_copy_constructible_v<T>, "");
    211         static_assert(std::is_same<decltype(ex::is_copy_constructible_v<T>), const bool>::value, "");
    212         static_assert(ex::is_copy_constructible_v<T> == std::is_copy_constructible<T>::value, "");
    213     }
    214     {
    215         typedef void T;
    216         static_assert(!ex::is_copy_constructible_v<T>, "");
    217         static_assert(ex::is_copy_constructible_v<T> == std::is_copy_constructible<T>::value, "");
    218     }
    219     {
    220         typedef int T;
    221         static_assert(ex::is_move_constructible_v<T>, "");
    222         static_assert(std::is_same<decltype(ex::is_move_constructible_v<T>), const bool>::value, "");
    223         static_assert(ex::is_move_constructible_v<T> == std::is_move_constructible<T>::value, "");
    224     }
    225     {
    226         typedef void T;
    227         static_assert(!ex::is_move_constructible_v<T>, "");
    228         static_assert(ex::is_move_constructible_v<T> == std::is_move_constructible<T>::value, "");
    229     }
    230     {
    231         typedef int & T;
    232         typedef int U;
    233         static_assert(ex::is_assignable_v<T, U>, "");
    234         static_assert(std::is_same<decltype(ex::is_assignable_v<T, U>), const bool>::value, "");
    235         static_assert(ex::is_assignable_v<T, U> == std::is_assignable<T, U>::value, "");
    236     }
    237     {
    238         typedef int & T;
    239         typedef void U;
    240         static_assert(!ex::is_assignable_v<T, U>, "");
    241         static_assert(ex::is_assignable_v<T, U> == std::is_assignable<T, U>::value, "");
    242     }
    243     {
    244         typedef int T;
    245         static_assert(ex::is_copy_assignable_v<T>, "");
    246         static_assert(std::is_same<decltype(ex::is_copy_assignable_v<T>), const bool>::value, "");
    247         static_assert(ex::is_copy_assignable_v<T> == std::is_copy_assignable<T>::value, "");
    248     }
    249     {
    250         typedef void T;
    251         static_assert(!ex::is_copy_assignable_v<T>, "");
    252         static_assert(ex::is_copy_assignable_v<T> == std::is_copy_assignable<T>::value, "");
    253     }
    254     {
    255         typedef int T;
    256         static_assert(ex::is_move_assignable_v<T>, "");
    257         static_assert(std::is_same<decltype(ex::is_move_assignable_v<T>), const bool>::value, "");
    258         static_assert(ex::is_move_assignable_v<T> == std::is_move_assignable<T>::value, "");
    259     }
    260     {
    261         typedef void T;
    262         static_assert(!ex::is_move_assignable_v<T>, "");
    263         static_assert(ex::is_move_assignable_v<T> == std::is_move_assignable<T>::value, "");
    264     }
    265     {
    266         typedef int T;
    267         static_assert(ex::is_destructible_v<T>, "");
    268         static_assert(std::is_same<decltype(ex::is_destructible_v<T>), const bool>::value, "");
    269         static_assert(ex::is_destructible_v<T> == std::is_destructible<T>::value, "");
    270     }
    271     {
    272         typedef void T;
    273         static_assert(!ex::is_destructible_v<T>, "");
    274         static_assert(ex::is_destructible_v<T> == std::is_destructible<T>::value, "");
    275     }
    276 }
    277 
    278 void is_trivially_constructible_and_assignable_test()
    279 {
    280     {
    281         typedef int T;
    282         static_assert(ex::is_trivially_constructible_v<T, int>, "");
    283         static_assert(std::is_same<decltype(ex::is_trivially_constructible_v<T, int>), const bool>::value, "");
    284         static_assert(ex::is_trivially_constructible_v<T, int> == std::is_constructible<T, int>::value, "");
    285     }
    286     {
    287         typedef void T;
    288         static_assert(!ex::is_trivially_constructible_v<T, int>, "");
    289         static_assert(ex::is_trivially_constructible_v<T, int> == std::is_constructible<T, int>::value, "");
    290     }
    291     {
    292         typedef int T;
    293         static_assert(ex::is_trivially_default_constructible_v<T>, "");
    294         static_assert(std::is_same<decltype(ex::is_trivially_default_constructible_v<T>), const bool>::value, "");
    295         static_assert(ex::is_trivially_default_constructible_v<T> == std::is_default_constructible<T>::value, "");
    296     }
    297     {
    298         typedef int & T;
    299         static_assert(!ex::is_trivially_default_constructible_v<T>, "");
    300         static_assert(ex::is_trivially_default_constructible_v<T> == std::is_default_constructible<T>::value, "");
    301     }
    302     {
    303         typedef int T;
    304         static_assert(ex::is_trivially_copy_constructible_v<T>, "");
    305         static_assert(std::is_same<decltype(ex::is_trivially_copy_constructible_v<T>), const bool>::value, "");
    306         static_assert(ex::is_trivially_copy_constructible_v<T> == std::is_copy_constructible<T>::value, "");
    307     }
    308     {
    309         typedef void T;
    310         static_assert(!ex::is_trivially_copy_constructible_v<T>, "");
    311         static_assert(ex::is_trivially_copy_constructible_v<T> == std::is_copy_constructible<T>::value, "");
    312     }
    313     {
    314         typedef int T;
    315         static_assert(ex::is_trivially_move_constructible_v<T>, "");
    316         static_assert(std::is_same<decltype(ex::is_trivially_move_constructible_v<T>), const bool>::value, "");
    317         static_assert(ex::is_trivially_move_constructible_v<T> == std::is_move_constructible<T>::value, "");
    318     }
    319     {
    320         typedef void T;
    321         static_assert(!ex::is_trivially_move_constructible_v<T>, "");
    322         static_assert(ex::is_trivially_move_constructible_v<T> == std::is_move_constructible<T>::value, "");
    323     }
    324     {
    325         typedef int & T;
    326         typedef int U;
    327         static_assert(ex::is_trivially_assignable_v<T, U>, "");
    328         static_assert(std::is_same<decltype(ex::is_trivially_assignable_v<T, U>), const bool>::value, "");
    329         static_assert(ex::is_trivially_assignable_v<T, U> == std::is_assignable<T, U>::value, "");
    330     }
    331     {
    332         typedef int & T;
    333         typedef void U;
    334         static_assert(!ex::is_trivially_assignable_v<T, U>, "");
    335         static_assert(ex::is_trivially_assignable_v<T, U> == std::is_assignable<T, U>::value, "");
    336     }
    337     {
    338         typedef int T;
    339         static_assert(ex::is_trivially_copy_assignable_v<T>, "");
    340         static_assert(std::is_same<decltype(ex::is_trivially_copy_assignable_v<T>), const bool>::value, "");
    341         static_assert(ex::is_trivially_copy_assignable_v<T> == std::is_copy_assignable<T>::value, "");
    342     }
    343     {
    344         typedef void T;
    345         static_assert(!ex::is_trivially_copy_assignable_v<T>, "");
    346         static_assert(ex::is_trivially_copy_assignable_v<T> == std::is_copy_assignable<T>::value, "");
    347     }
    348     {
    349         typedef int T;
    350         static_assert(ex::is_trivially_move_assignable_v<T>, "");
    351         static_assert(std::is_same<decltype(ex::is_trivially_move_assignable_v<T>), const bool>::value, "");
    352         static_assert(ex::is_trivially_move_assignable_v<T> == std::is_move_assignable<T>::value, "");
    353     }
    354     {
    355         typedef void T;
    356         static_assert(!ex::is_trivially_move_assignable_v<T>, "");
    357         static_assert(ex::is_trivially_move_assignable_v<T> == std::is_move_assignable<T>::value, "");
    358     }
    359     {
    360         typedef int T;
    361         static_assert(ex::is_trivially_destructible_v<T>, "");
    362         static_assert(std::is_same<decltype(ex::is_trivially_destructible_v<T>), const bool>::value, "");
    363         static_assert(ex::is_trivially_destructible_v<T> == std::is_destructible<T>::value, "");
    364     }
    365     {
    366         typedef void T;
    367         static_assert(!ex::is_trivially_destructible_v<T>, "");
    368         static_assert(ex::is_trivially_destructible_v<T> == std::is_destructible<T>::value, "");
    369     }
    370 }
    371 
    372 
    373 
    374 void is_nothrow_constructible_and_assignable_test()
    375 {
    376     {
    377         typedef int T;
    378         static_assert(ex::is_nothrow_constructible_v<T, int>, "");
    379         static_assert(std::is_same<decltype(ex::is_nothrow_constructible_v<T, int>), const bool>::value, "");
    380         static_assert(ex::is_nothrow_constructible_v<T, int> == std::is_constructible<T, int>::value, "");
    381     }
    382     {
    383         typedef void T;
    384         static_assert(!ex::is_nothrow_constructible_v<T, int>, "");
    385         static_assert(ex::is_nothrow_constructible_v<T, int> == std::is_constructible<T, int>::value, "");
    386     }
    387     {
    388         typedef int T;
    389         static_assert(ex::is_nothrow_default_constructible_v<T>, "");
    390         static_assert(std::is_same<decltype(ex::is_nothrow_default_constructible_v<T>), const bool>::value, "");
    391         static_assert(ex::is_nothrow_default_constructible_v<T> == std::is_default_constructible<T>::value, "");
    392     }
    393     {
    394         typedef int & T;
    395         static_assert(!ex::is_nothrow_default_constructible_v<T>, "");
    396         static_assert(ex::is_nothrow_default_constructible_v<T> == std::is_default_constructible<T>::value, "");
    397     }
    398     {
    399         typedef int T;
    400         static_assert(ex::is_nothrow_copy_constructible_v<T>, "");
    401         static_assert(std::is_same<decltype(ex::is_nothrow_copy_constructible_v<T>), const bool>::value, "");
    402         static_assert(ex::is_nothrow_copy_constructible_v<T> == std::is_copy_constructible<T>::value, "");
    403     }
    404     {
    405         typedef void T;
    406         static_assert(!ex::is_nothrow_copy_constructible_v<T>, "");
    407         static_assert(ex::is_nothrow_copy_constructible_v<T> == std::is_copy_constructible<T>::value, "");
    408     }
    409     {
    410         typedef int T;
    411         static_assert(ex::is_nothrow_move_constructible_v<T>, "");
    412         static_assert(std::is_same<decltype(ex::is_nothrow_move_constructible_v<T>), const bool>::value, "");
    413         static_assert(ex::is_nothrow_move_constructible_v<T> == std::is_move_constructible<T>::value, "");
    414     }
    415     {
    416         typedef void T;
    417         static_assert(!ex::is_nothrow_move_constructible_v<T>, "");
    418         static_assert(ex::is_nothrow_move_constructible_v<T> == std::is_move_constructible<T>::value, "");
    419     }
    420     {
    421         typedef int & T;
    422         typedef int U;
    423         static_assert(ex::is_nothrow_assignable_v<T, U>, "");
    424         static_assert(std::is_same<decltype(ex::is_nothrow_assignable_v<T, U>), const bool>::value, "");
    425         static_assert(ex::is_nothrow_assignable_v<T, U> == std::is_assignable<T, U>::value, "");
    426     }
    427     {
    428         typedef int & T;
    429         typedef void U;
    430         static_assert(!ex::is_nothrow_assignable_v<T, U>, "");
    431         static_assert(ex::is_nothrow_assignable_v<T, U> == std::is_assignable<T, U>::value, "");
    432     }
    433     {
    434         typedef int T;
    435         static_assert(ex::is_nothrow_copy_assignable_v<T>, "");
    436         static_assert(std::is_same<decltype(ex::is_nothrow_copy_assignable_v<T>), const bool>::value, "");
    437         static_assert(ex::is_nothrow_copy_assignable_v<T> == std::is_copy_assignable<T>::value, "");
    438     }
    439     {
    440         typedef void T;
    441         static_assert(!ex::is_nothrow_copy_assignable_v<T>, "");
    442         static_assert(ex::is_nothrow_copy_assignable_v<T> == std::is_copy_assignable<T>::value, "");
    443     }
    444     {
    445         typedef int T;
    446         static_assert(ex::is_nothrow_move_assignable_v<T>, "");
    447         static_assert(std::is_same<decltype(ex::is_nothrow_move_assignable_v<T>), const bool>::value, "");
    448         static_assert(ex::is_nothrow_move_assignable_v<T> == std::is_move_assignable<T>::value, "");
    449     }
    450     {
    451         typedef void T;
    452         static_assert(!ex::is_nothrow_move_assignable_v<T>, "");
    453         static_assert(ex::is_nothrow_move_assignable_v<T> == std::is_move_assignable<T>::value, "");
    454     }
    455     {
    456         typedef int T;
    457         static_assert(ex::is_nothrow_destructible_v<T>, "");
    458         static_assert(std::is_same<decltype(ex::is_nothrow_destructible_v<T>), const bool>::value, "");
    459         static_assert(ex::is_nothrow_destructible_v<T> == std::is_destructible<T>::value, "");
    460     }
    461     {
    462         typedef void T;
    463         static_assert(!ex::is_nothrow_destructible_v<T>, "");
    464         static_assert(ex::is_nothrow_destructible_v<T> == std::is_destructible<T>::value, "");
    465     }
    466 }
    467 
    468 int main()
    469 {
    470     type_properties_test();
    471     is_constructible_and_assignable_test();
    472     is_trivially_constructible_and_assignable_test();
    473     is_nothrow_constructible_and_assignable_test();
    474     {
    475         typedef virtual_dtor_type T;
    476         static_assert(ex::has_virtual_destructor_v<T>, "");
    477         static_assert(std::is_same<decltype(ex::has_virtual_destructor_v<T>), const bool>::value, "");
    478         static_assert(ex::has_virtual_destructor_v<T> == std::has_virtual_destructor<T>::value, "");
    479     }
    480     {
    481         typedef int T;
    482         static_assert(!ex::has_virtual_destructor_v<T>, "");
    483         static_assert(ex::has_virtual_destructor_v<T> == std::has_virtual_destructor<T>::value, "");
    484     }
    485 }
    486 
    487