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 lastweek_weekday
24 // {
25 //     iso_week::weekday wd_;  // exposition only
26 //
27 // public:
28 //     explicit constexpr lastweek_weekday(const iso_week::weekday& wd) noexcept;
29 //
30 //     constexpr iso_week::weekday weekday() const noexcept;
31 //
32 //     constexpr bool ok() const noexcept;
33 // };
34 //
35 // constexpr bool operator==(const lastweek_weekday& x, const lastweek_weekday& y) noexcept;
36 // constexpr bool operator!=(const lastweek_weekday& x, const lastweek_weekday& y) noexcept;
37 // constexpr bool operator< (const lastweek_weekday& x, const lastweek_weekday& y) noexcept;
38 // constexpr bool operator> (const lastweek_weekday& x, const lastweek_weekday& y) noexcept;
39 // constexpr bool operator<=(const lastweek_weekday& x, const lastweek_weekday& y) noexcept;
40 // constexpr bool operator>=(const lastweek_weekday& x, const lastweek_weekday& y) noexcept;
41 //
42 // std::ostream& operator<<(std::ostream& os, const lastweek_weekday& md);
43 
44 #include "iso_week.h"
45 
46 #include <cassert>
47 #include <sstream>
48 #include <type_traits>
49 
50 static_assert( std::is_trivially_destructible<iso_week::lastweek_weekday>{}, "");
51 static_assert(!std::is_default_constructible<iso_week::lastweek_weekday>{}, "");
52 static_assert( std::is_trivially_copy_constructible<iso_week::lastweek_weekday>{}, "");
53 static_assert( std::is_trivially_copy_assignable<iso_week::lastweek_weekday>{}, "");
54 static_assert( std::is_trivially_move_constructible<iso_week::lastweek_weekday>{}, "");
55 static_assert( std::is_trivially_move_assignable<iso_week::lastweek_weekday>{}, "");
56 
57 static_assert(std::is_trivially_copyable<iso_week::lastweek_weekday>{}, "");
58 static_assert(std::is_standard_layout<iso_week::lastweek_weekday>{}, "");
59 static_assert(std::is_literal_type<iso_week::lastweek_weekday>{}, "");
60 
61 static_assert( std::is_nothrow_constructible<iso_week::lastweek_weekday,
62                                                  iso_week::weekday>{}, "");
63 static_assert(!std::is_convertible<iso_week::weekday, iso_week::lastweek_weekday>{}, "");
64 
65 int
main()66 main()
67 {
68     using namespace iso_week;
69 
70     constexpr auto wn_wd = lastweek_weekday{tue};
71     static_assert(wn_wd.weekday() == tue, "");
72 
73     static_assert(wn_wd.ok(), "");
74 
75     static_assert(wn_wd == lastweek_weekday{tue}, "");
76     static_assert(!(wn_wd != lastweek_weekday{tue}), "");
77     static_assert(wn_wd < lastweek_weekday{wed}, "");
78 
79     std::ostringstream os;
80     os << wn_wd;
81     assert(os.str() == "W last-Tue");
82 }
83