]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/std/language.support/support.types/byteops/to_integer.pass.cpp
Vendor import of libc++ trunk r303197:
[FreeBSD/FreeBSD.git] / test / std / language.support / support.types / byteops / to_integer.pass.cpp
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 #include <cstddef>
11 #include <test_macros.h>
12
13 // UNSUPPORTED: c++98, c++03, c++11, c++14
14
15 // template <class IntegerType>
16 //    constexpr IntegerType to_integer(byte b) noexcept;
17 // This function shall not participate in overload resolution unless
18 //   is_integral_v<IntegerType> is true.
19
20 int main () {
21         constexpr std::byte b1{static_cast<std::byte>(1)};
22         constexpr std::byte b3{static_cast<std::byte>(3)};
23
24         static_assert(noexcept(std::to_integer<int>(b1)), "" );
25         static_assert(std::is_same<int, decltype(std::to_integer<int>(b1))>::value, "" );
26         static_assert(std::is_same<long, decltype(std::to_integer<long>(b1))>::value, "" );
27         static_assert(std::is_same<unsigned short, decltype(std::to_integer<unsigned short>(b1))>::value, "" );
28
29         static_assert(std::to_integer<int>(b1) == 1, "");
30         static_assert(std::to_integer<int>(b3) == 3, "");
31 }