-
Notifications
You must be signed in to change notification settings - Fork 124
Expand file tree
/
Copy pathnarrow_cast.cpp
More file actions
34 lines (24 loc) · 921 Bytes
/
narrow_cast.cpp
File metadata and controls
34 lines (24 loc) · 921 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Copyright (C) 2016-2020 Jonathan Müller <[email protected]>
// This file is subject to the license terms in the LICENSE file
// found in the top-level directory of this distribution.
#include <type_safe/narrow_cast.hpp>
#include <catch.hpp>
using namespace type_safe;
TEST_CASE("narrow_cast<integer>")
{
integer<int> a(4);
integer<short> b = narrow_cast<short>(a);
REQUIRE(static_cast<short>(b) == 4);
integer<short> c = narrow_cast<integer<short>>(a);
REQUIRE(static_cast<short>(c) == 4);
integer<short> d = narrow_cast<integer<short>>(42);
REQUIRE(static_cast<short>(d) == 42);
}
TEST_CASE("narrow_cast<floating_point>")
{
floating_point<double> a(1.);
floating_point<float> b = narrow_cast<float>(a);
REQUIRE(static_cast<float>(b) == 1.);
floating_point<float> c = narrow_cast<floating_point<float>>(a);
REQUIRE(static_cast<float>(c) == 1.);
}