1 // The MIT License (MIT)
2 //
3 // Copyright (c) 2015, 2016 Howard Hinnant
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to deal
7 // in the Software without restriction, including without limitation the rights
8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 // copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be included in all
13 // copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 // SOFTWARE.
22
23 // class weeknum_weekday
24 // {
25 // iso_week::weeknum wn_; // exposition only
26 // iso_week::weekday wd_; // exposition only
27 //
28 // public:
29 // constexpr weeknum_weekday(const iso_week::weeknum& wn,
30 // const iso_week::weekday& wd) noexcept;
31 //
32 // constexpr iso_week::weeknum weeknum() const noexcept;
33 // constexpr iso_week::weekday weekday() const noexcept;
34 //
35 // constexpr bool ok() const noexcept;
36 // };
37 //
38 // constexpr bool operator==(const weeknum_weekday& x, const weeknum_weekday& y) noexcept;
39 // constexpr bool operator!=(const weeknum_weekday& x, const weeknum_weekday& y) noexcept;
40 // constexpr bool operator< (const weeknum_weekday& x, const weeknum_weekday& y) noexcept;
41 // constexpr bool operator> (const weeknum_weekday& x, const weeknum_weekday& y) noexcept;
42 // constexpr bool operator<=(const weeknum_weekday& x, const weeknum_weekday& y) noexcept;
43 // constexpr bool operator>=(const weeknum_weekday& x, const weeknum_weekday& y) noexcept;
44 //
45 // std::ostream& operator<<(std::ostream& os, const weeknum_weekday& md);
46
47 #include "iso_week.h"
48
49 #include <cassert>
50 #include <sstream>
51 #include <type_traits>
52
53 static_assert( std::is_trivially_destructible<iso_week::weeknum_weekday>{}, "");
54 static_assert(!std::is_default_constructible<iso_week::weeknum_weekday>{}, "");
55 static_assert( std::is_trivially_copy_constructible<iso_week::weeknum_weekday>{}, "");
56 static_assert( std::is_trivially_copy_assignable<iso_week::weeknum_weekday>{}, "");
57 static_assert( std::is_trivially_move_constructible<iso_week::weeknum_weekday>{}, "");
58 static_assert( std::is_trivially_move_assignable<iso_week::weeknum_weekday>{}, "");
59
60 static_assert(std::is_trivially_copyable<iso_week::weeknum_weekday>{}, "");
61 static_assert(std::is_standard_layout<iso_week::weeknum_weekday>{}, "");
62 static_assert(std::is_literal_type<iso_week::weeknum_weekday>{}, "");
63
64 static_assert( std::is_nothrow_constructible<iso_week::weeknum_weekday,
65 iso_week::weeknum,
66 iso_week::weekday>{}, "");
67
68 int
main()69 main()
70 {
71 using namespace iso_week;
72
73 constexpr auto wn_wd = weeknum_weekday{52_w, tue};
74 static_assert(wn_wd.weeknum() == 52_w, "");
75 static_assert(wn_wd.weekday() == tue, "");
76
77 static_assert(wn_wd.ok(), "");
78
79 static_assert(wn_wd == weeknum_weekday{52_w, tue}, "");
80 static_assert(!(wn_wd != weeknum_weekday{52_w, tue}), "");
81 static_assert(wn_wd < weeknum_weekday{52_w, wed}, "");
82
83 std::ostringstream os;
84 os << wn_wd;
85 assert(os.str() == "W52-Tue");
86 }
87