// The MIT License (MIT) // // Copyright (c) 2019 Tomasz KamiƄski // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in all // copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. #include "tz.h" #include "OffsetZone.h" #include #include #include #if HAS_DEDUCTION_GUIDES #include template void testDeductionFrom(Source&& s) { using namespace date; using namespace std::chrono; using date::sys_time, date::local_days, date::local_time; // No time point { zoned_time zt(std::forward(s)); static_assert(std::is_same>::value, ""); } // sys_time { sys_days sd(2017_y/feb/20); zoned_time ztd(std::forward(s), sd); static_assert(std::is_same>::value, ""); sys_time ss(sd); zoned_time zts(std::forward(s), ss); static_assert(std::is_same>::value, ""); sys_time sms(ss); zoned_time ztms(std::forward(s), sms); static_assert(std::is_same>::value, ""); } // local_time { local_days ld(2017_y/feb/20); zoned_time ztd(std::forward(s), ld); static_assert(std::is_same>::value, ""); local_time ls(ld); zoned_time zts(std::forward(s), ls); static_assert(std::is_same>::value, ""); local_time lms(ls); zoned_time ztms(std::forward(s), lms); static_assert(std::is_same>::value, ""); } // local_time, choose { local_days ld(2017_y/feb/20); zoned_time ztd(std::forward(s), ld, choose::earliest); static_assert(std::is_same>::value, ""); local_time ls(ld); zoned_time zts(std::forward(s), ls, choose::earliest); static_assert(std::is_same>::value, ""); local_time lms(ls); zoned_time ztms(std::forward(s), lms, choose::earliest); static_assert(std::is_same>::value, ""); } // zoned_time { zoned_time zd(sys_days(2017_y/feb/20)); zoned_time ztd(std::forward(s), zd); static_assert(std::is_same>::value, ""); zoned_time zs(zd); zoned_time zts(std::forward(s), zs); static_assert(std::is_same>::value, ""); zoned_time zms(zs); zoned_time ztms(std::forward(s), zms); static_assert(std::is_same>::value, ""); } // zoned_time, choose { zoned_time zd(sys_days(2017_y/feb/20)); zoned_time ztd(std::forward(s), zd, choose::earliest); static_assert(std::is_same>::value, ""); zoned_time zs(zd); zoned_time zts(std::forward(s), zs, choose::earliest); static_assert(std::is_same>::value, ""); zoned_time zms(zs); zoned_time ztms(std::forward(s), zms, choose::earliest); static_assert(std::is_same>::value, ""); } } struct MyString { MyString(std::string s) : ms(std::move(s)) {} operator std::string_view() const { return ms; } private: std::string ms; }; struct OnlyLValueString { OnlyLValueString(std::string s) : ms(std::move(s)) {} operator std::string_view() & { return ms; } private: std::string ms; }; #endif // HAS_DEDUCTION_GUIDES template T const& to_const(T& t) { return t; } int main() { using namespace date; using namespace std::chrono; using date::sys_time, date::local_days, date::local_time; #if HAS_DEDUCTION_GUIDES // no arguments { zoned_time zt{}; static_assert(std::is_same>::value, ""); } // zoned_time { zoned_time zd(sys_days(2017_y/feb/20)); zoned_time ztd(zd); static_assert(std::is_same>::value, ""); zoned_time zs(zd); zoned_time zts(zs); static_assert(std::is_same>::value, ""); zoned_time zms(zs); zoned_time ztms(zms); static_assert(std::is_same>::value, ""); } // sys_time { sys_days sd(2017_y/feb/20); zoned_time ztd(sd); static_assert(std::is_same>::value, ""); sys_time ss(sd); zoned_time zts(ss); static_assert(std::is_same>::value, ""); sys_time sms(ss); zoned_time ztms(sms); static_assert(std::is_same>::value, ""); } // time_zone const* { time_zone const* tz = current_zone(); testDeductionFrom(tz); testDeductionFrom(to_const(tz)); testDeductionFrom(std::move(tz)); } // char const* { char const* tz = "Europe/Warsaw"; testDeductionFrom(tz); testDeductionFrom(to_const(tz)); testDeductionFrom(std::move(tz)); } // std::string { std::string tz = "Europe/Warsaw"; testDeductionFrom(tz); testDeductionFrom(to_const(tz)); testDeductionFrom(std::move(tz)); } // std::string_view { std::string_view tz = "Europe/Warsaw"; testDeductionFrom(tz); testDeductionFrom(to_const(tz)); testDeductionFrom(std::move(tz)); } // MyString { MyString tz("Europe/Warsaw"); testDeductionFrom(tz); testDeductionFrom(to_const(tz)); testDeductionFrom(std::move(tz)); } // custom time zone { OffsetZone tz(minutes(45)); testDeductionFrom(tz); testDeductionFrom(to_const(tz)); testDeductionFrom(std::move(tz)); } // OnlyLValue { OnlyLValueString tz("Europe/Warsaw"); testDeductionFrom(tz); //testDeductionFrom(to_const(tz)); //testDeductionFrom(std::move(tz)); } #endif // HAS_DEDUCTION_GUIDES }