Example #1
0
int main()
{
    using month  = std::chrono::month;
    using months = std::chrono::months;

    ASSERT_NOEXCEPT(std::declval<month>() + std::declval<months>());
    ASSERT_NOEXCEPT(std::declval<months>() + std::declval<month>());

    ASSERT_SAME_TYPE(month, decltype(std::declval<month>()  + std::declval<months>()));
    ASSERT_SAME_TYPE(month, decltype(std::declval<months>() + std::declval<month>() ));

    static_assert(testConstexpr<month, months>(), "");

    month my{2};
    for (unsigned i = 0; i <= 15; ++i)
    {
        month m1 = my + months{i};
        month m2 = months{i} + my;
        assert(m1 == m2);
        unsigned exp = i + 2;
        while (exp > 12)
            exp -= 12;
        assert(static_cast<unsigned>(m1) == exp);
        assert(static_cast<unsigned>(m2) == exp);
    }
}
Example #2
0
int main(int, char**)
{
    using year           = std::chrono::year;
    using month          = std::chrono::month;
    using day            = std::chrono::day;
    using year_month_day = std::chrono::year_month_day;

    ASSERT_NOEXCEPT(year_month_day{});
    ASSERT_NOEXCEPT(year_month_day{year{1}, month{1}, day{1}});

    constexpr month January = std::chrono::January;

    constexpr year_month_day ym0{};
    static_assert( ym0.year()  == year{},  "");
    static_assert( ym0.month() == month{}, "");
    static_assert( ym0.day()   == day{},   "");
    static_assert(!ym0.ok(),               "");

    constexpr year_month_day ym1{year{2019}, January, day{12}};
    static_assert( ym1.year()  == year{2019}, "");
    static_assert( ym1.month() == January,    "");
    static_assert( ym1.day()   == day{12},    "");
    static_assert( ym1.ok(),                  "");


  return 0;
}
Example #3
0
int main(int, char**)
{
    using year = std::chrono::year;

    ASSERT_NOEXCEPT(                std::declval<const year>().ok());
    ASSERT_SAME_TYPE(bool, decltype(std::declval<const year>().ok()));

    ASSERT_NOEXCEPT(                year::max());
    ASSERT_SAME_TYPE(year, decltype(year::max()));

    ASSERT_NOEXCEPT(                year::min());
    ASSERT_SAME_TYPE(year, decltype(year::min()));

    static_assert(static_cast<int>(year::min()) == -32767, "");
    static_assert(static_cast<int>(year::max()) ==  32767, "");

    assert(year{-20001}.ok());
    assert(year{ -2000}.ok());
    assert(year{    -1}.ok());
    assert(year{     0}.ok());
    assert(year{     1}.ok());
    assert(year{  2000}.ok());
    assert(year{ 20001}.ok());

    static_assert(!year{-32768}.ok(), "");

  return 0;
}
Example #4
0
int main(int, char**)
{
    {
    typedef std::list<int> C;
    C c;
    ASSERT_NOEXCEPT(c.empty());
    assert(c.empty());
    c.push_back(C::value_type(1));
    assert(!c.empty());
    c.clear();
    assert(c.empty());
    }
#if TEST_STD_VER >= 11
    {
    typedef std::list<int, min_allocator<int>> C;
    C c;
    ASSERT_NOEXCEPT(c.empty());
    assert(c.empty());
    c.push_back(C::value_type(1));
    assert(!c.empty());
    c.clear();
    assert(c.empty());
    }
#endif

  return 0;
}
Example #5
0
int main()
{
    using weekday  = std::chrono::weekday;
    using weekday_indexed = std::chrono::weekday_indexed;

    ASSERT_NOEXCEPT(weekday_indexed{});
    ASSERT_NOEXCEPT(weekday_indexed(weekday{1}, 1));

    constexpr weekday_indexed wdi0{};
    static_assert( wdi0.weekday() == weekday{}, "");
    static_assert( wdi0.index() == 0,           "");
    static_assert(!wdi0.ok(),                   "");

    constexpr weekday_indexed wdi1{std::chrono::Sunday, 2};
    static_assert( wdi1.weekday() == std::chrono::Sunday, "");
    static_assert( wdi1.index() == 2,                     "");
    static_assert( wdi1.ok(),                             "");

    for (unsigned i = 1; i <= 5; ++i)
    {
        weekday_indexed wdi(std::chrono::Tuesday, i);
        assert( wdi.weekday() == std::chrono::Tuesday);
        assert( wdi.index() == i);
        assert( wdi.ok());
    }

    for (unsigned i = 6; i <= 20; ++i)
    {
        weekday_indexed wdi(std::chrono::Tuesday, i);
        assert(!wdi.ok());
    }
}
Example #6
0
int main(int, char**)
{
    using weekday  = std::chrono::weekday;
    using days     = std::chrono::days;

    ASSERT_NOEXCEPT(                   std::declval<weekday>() - std::declval<days>());
    ASSERT_SAME_TYPE(weekday, decltype(std::declval<weekday>() - std::declval<days>()));

    ASSERT_NOEXCEPT(                   std::declval<weekday>() - std::declval<weekday>());
    ASSERT_SAME_TYPE(days,    decltype(std::declval<weekday>() - std::declval<weekday>()));

    static_assert(testConstexpr<weekday, days>(), "");

    for (unsigned i = 0; i <= 6; ++i)
        for (unsigned j = 0; j <= 6; ++j)
        {
            weekday wd = weekday{i} - days{j};
            assert(wd + days{j} == weekday{i});
            assert((static_cast<unsigned>(wd) == euclidian_subtraction<unsigned, 0, 6>(i, j)));
        }

    for (unsigned i = 0; i <= 6; ++i)
        for (unsigned j = 0; j <= 6; ++j)
        {
            days d = weekday{j} - weekday{i};
            assert(weekday{i} + d == weekday{j});
        }


  return 0;
}
Example #7
0
int main()
{
    using day        = std::chrono::day;
    using year       = std::chrono::year;
    using years      = std::chrono::years;
    using month      = std::chrono::month;
    using months     = std::chrono::months;
    using year_month_day = std::chrono::year_month_day;

    {   // year_month_day + months
    ASSERT_NOEXCEPT(std::declval<year_month_day>() + std::declval<months>());
    ASSERT_NOEXCEPT(std::declval<months>() + std::declval<year_month_day>());

    ASSERT_SAME_TYPE(year_month_day, decltype(std::declval<year_month_day>() + std::declval<months>()));
    ASSERT_SAME_TYPE(year_month_day, decltype(std::declval<months>() + std::declval<year_month_day>()));

    static_assert(testConstexprMonths(year_month_day{year{1}, month{1}, day{1}}), "");

    year_month_day ym{year{1234}, std::chrono::January, day{12}};
    for (int i = 0; i <= 10; ++i)  // TODO test wrap-around
    {
        year_month_day ym1 = ym + months{i};
        year_month_day ym2 = months{i} + ym;
        assert(static_cast<int>(ym1.year()) == 1234);
        assert(static_cast<int>(ym2.year()) == 1234);
        assert(ym1.month() == month(1 + i));
        assert(ym2.month() == month(1 + i));
        assert(ym1.day()   == day{12});
        assert(ym2.day()   == day{12});
        assert(ym1 == ym2);
    }
    }

    {   // year_month_day + years
    ASSERT_NOEXCEPT(std::declval<year_month_day>() + std::declval<years>());
    ASSERT_NOEXCEPT(std::declval<years>() + std::declval<year_month_day>());

    ASSERT_SAME_TYPE(year_month_day, decltype(std::declval<year_month_day>() + std::declval<years>()));
    ASSERT_SAME_TYPE(year_month_day, decltype(std::declval<years>() + std::declval<year_month_day>()));

    static_assert(testConstexprYears (year_month_day{year{1}, month{1}, day{1}}), "");

    year_month_day ym{year{1234}, std::chrono::January, day{12}};
    for (int i = 0; i <= 10; ++i)
    {
        year_month_day ym1 = ym + years{i};
        year_month_day ym2 = years{i} + ym;
        assert(static_cast<int>(ym1.year()) == i + 1234);
        assert(static_cast<int>(ym2.year()) == i + 1234);
        assert(ym1.month() == std::chrono::January);
        assert(ym2.month() == std::chrono::January);
        assert(ym1.day()   == day{12});
        assert(ym2.day()   == day{12});
        assert(ym1 == ym2);
    }
    }

}
Example #8
0
void test_const_lvalue_get() {
  {
    using V = std::variant<int, const long>;
    constexpr V v(42);
#ifndef __clang__ // Avoid https://llvm.org/bugs/show_bug.cgi?id=15481
    ASSERT_NOEXCEPT(std::get<0>(v));
#endif
    ASSERT_SAME_TYPE(decltype(std::get<0>(v)), const int &);
    static_assert(std::get<0>(v) == 42, "");
  }
  {
    using V = std::variant<int, const long>;
    const V v(42);
    ASSERT_NOT_NOEXCEPT(std::get<0>(v));
    ASSERT_SAME_TYPE(decltype(std::get<0>(v)), const int &);
    assert(std::get<0>(v) == 42);
  }
  {
    using V = std::variant<int, const long>;
    constexpr V v(42l);
#ifndef __clang__ // Avoid https://llvm.org/bugs/show_bug.cgi?id=15481
    ASSERT_NOEXCEPT(std::get<1>(v));
#endif
    ASSERT_SAME_TYPE(decltype(std::get<1>(v)), const long &);
    static_assert(std::get<1>(v) == 42, "");
  }
  {
    using V = std::variant<int, const long>;
    const V v(42l);
    ASSERT_NOT_NOEXCEPT(std::get<1>(v));
    ASSERT_SAME_TYPE(decltype(std::get<1>(v)), const long &);
    assert(std::get<1>(v) == 42);
  }
// FIXME: Remove these once reference support is reinstated
#if !defined(TEST_VARIANT_HAS_NO_REFERENCES)
  {
    using V = std::variant<int &>;
    int x = 42;
    const V v(x);
    ASSERT_SAME_TYPE(decltype(std::get<0>(v)), int &);
    assert(&std::get<0>(v) == &x);
  }
  {
    using V = std::variant<int &&>;
    int x = 42;
    const V v(std::move(x));
    ASSERT_SAME_TYPE(decltype(std::get<0>(v)), int &);
    assert(&std::get<0>(v) == &x);
  }
  {
    using V = std::variant<const int &&>;
    int x = 42;
    const V v(std::move(x));
    ASSERT_SAME_TYPE(decltype(std::get<0>(v)), const int &);
    assert(&std::get<0>(v) == &x);
  }
#endif
}
Example #9
0
int main(int, char**)
{
    using year           = std::chrono::year;
    using month          = std::chrono::month;
    using day            = std::chrono::day;
    using year_month_day = std::chrono::year_month_day;
    using years          = std::chrono::years;

    ASSERT_NOEXCEPT(                          std::declval<year_month_day>() - std::declval<years>());
    ASSERT_SAME_TYPE(year_month_day, decltype(std::declval<year_month_day>() - std::declval<years>()));

    constexpr month January = std::chrono::January;

    static_assert(test_constexpr(), "");

    year_month_day ym{year{1234}, January, day{10}};
    for (int i = 0; i <= 10; ++i)
    {
        year_month_day ym1 = ym - years{i};
        assert(static_cast<int>(ym1.year()) == 1234 - i);
        assert(ym1.month() == January);
        assert(ym1.day() == day{10});
    }

  return 0;
}
Example #10
0
int main(int, char**)
{
    using month              = std::chrono::month;
    using weekday            = std::chrono::weekday;
    using weekday_last       = std::chrono::weekday_last;
    using month_weekday_last = std::chrono::month_weekday_last;

    constexpr month January = std::chrono::January;
    constexpr weekday Tuesday = std::chrono::Tuesday;

    ASSERT_NOEXCEPT(month_weekday_last{January, weekday_last{Tuesday}});

//  bad month
    constexpr month_weekday_last mwdl1{month{}, weekday_last{Tuesday}};
    static_assert( mwdl1.month() == month{},                      "");
    static_assert( mwdl1.weekday_last() == weekday_last{Tuesday}, "");
    static_assert(!mwdl1.ok(),                                    "");

//  bad weekday_last
    constexpr month_weekday_last mwdl2{January, weekday_last{weekday{16}}};
    static_assert( mwdl2.month() == January,                          "");
    static_assert( mwdl2.weekday_last() == weekday_last{weekday{16}}, "");
    static_assert(!mwdl2.ok(),                                        "");

//  Good month and weekday_last
    constexpr month_weekday_last mwdl3{January, weekday_last{weekday{4}}};
    static_assert( mwdl3.month() == January,                         "");
    static_assert( mwdl3.weekday_last() == weekday_last{weekday{4}}, "");
    static_assert( mwdl3.ok(),                                       "");

  return 0;
}
Example #11
0
int main(int, char**)
{
    using year                = std::chrono::year;
    using month               = std::chrono::month;
    using month_day_last      = std::chrono::month_day_last;
    using year_month_day_last = std::chrono::year_month_day_last;

    ASSERT_NOEXCEPT(year_month_day_last{year{1}, month_day_last{month{1}}});

    constexpr month January = std::chrono::January;

    constexpr year_month_day_last ymdl0{year{}, month_day_last{month{}}};
    static_assert( ymdl0.year()           == year{},                  "");
    static_assert( ymdl0.month()          == month{},                 "");
    static_assert( ymdl0.month_day_last() == month_day_last{month{}}, "");
    static_assert(!ymdl0.ok(),                                        "");

    constexpr year_month_day_last ymdl1{year{2019}, month_day_last{January}};
    static_assert( ymdl1.year()           == year{2019},              "");
    static_assert( ymdl1.month()          == January,                 "");
    static_assert( ymdl1.month_day_last() == month_day_last{January}, "");
    static_assert( ymdl1.ok(),                                        "");

  return 0;
}
Example #12
0
static int
test(const S& s)
{
    ASSERT_NOEXCEPT(s.empty());
    TC_ASSERT_EXPR(s.empty() == (s.size() == 0));
    return 0;
}
Example #13
0
int main()
{
    using day       = std::chrono::day;
    using month     = std::chrono::month;
    using month_day = std::chrono::month_day;

    ASSERT_NOEXCEPT(                std::declval<const month_day>().ok());
    ASSERT_SAME_TYPE(bool, decltype(std::declval<const month_day>().ok()));

    static_assert(!month_day{}.ok(),                         "");
    static_assert( month_day{std::chrono::May, day{2}}.ok(), "");

    assert(!(month_day(std::chrono::April, day{0}).ok()));

    assert( (month_day{std::chrono::March, day{1}}.ok()));
    for (unsigned i = 1; i <= 12; ++i)
    {
        const bool is31 = i == 1 || i == 3 || i == 5 || i == 7 || i == 8 || i == 10 || i == 12;
        assert(!(month_day{month{i}, day{ 0}}.ok()));
        assert( (month_day{month{i}, day{ 1}}.ok()));
        assert( (month_day{month{i}, day{10}}.ok()));
        assert( (month_day{month{i}, day{29}}.ok()));
        assert( (month_day{month{i}, day{30}}.ok()) == (i != 2));
        assert( (month_day{month{i}, day{31}}.ok()) == is31);
        assert(!(month_day{month{i}, day{32}}.ok()));
    }

//  If the month is not ok, all the days are bad
    for (unsigned i = 1; i <= 35; ++i)
        assert(!(month_day{month{13}, day{i}}.ok()));
}
Example #14
0
int main()
{
    using year                = std::chrono::year;
    using month               = std::chrono::month;
    using month_day_last      = std::chrono::month_day_last;
    using year_month_day_last = std::chrono::year_month_day_last;

    constexpr month January = std::chrono::January;

    ASSERT_NOEXCEPT(                std::declval<const year_month_day_last>().ok());
    ASSERT_SAME_TYPE(bool, decltype(std::declval<const year_month_day_last>().ok()));

    static_assert(!year_month_day_last{year{-32768}, month_day_last{month{}}}.ok(), ""); // both bad
    static_assert(!year_month_day_last{year{-32768}, month_day_last{January}}.ok(), ""); // Bad year
    static_assert(!year_month_day_last{year{2019},   month_day_last{month{}}}.ok(), ""); // Bad month
    static_assert( year_month_day_last{year{2019},   month_day_last{January}}.ok(), ""); // All OK

    for (unsigned i = 0; i <= 50; ++i)
    {
        year_month_day_last ym{year{2019}, month_day_last{month{i}}};
        assert( ym.ok() == month{i}.ok());
    }

    const int ymax = static_cast<int>(year::max());
    for (int i = ymax - 100; i <= ymax + 100; ++i)
    {
        year_month_day_last ym{year{i}, month_day_last{January}};
        assert( ym.ok() == year{i}.ok());
    }
}
int main(int, char**)
{
    {
    typedef std::string_view SV;
    SV  sv1 {};
    SV  sv2 { "abcde", 5 };

    ASSERT_NOEXCEPT(sv1.starts_with('e'));

    assert (!sv1.starts_with('a'));
    assert (!sv1.starts_with('x'));
    assert ( sv2.starts_with('a'));
    assert (!sv2.starts_with('x'));
    }

#if TEST_STD_VER > 11
    {
    typedef std::basic_string_view<char, constexpr_char_traits<char>> SV;
    constexpr SV  sv1 {};
    constexpr SV  sv2 { "abcde", 5 };
    static_assert (!sv1.starts_with('a'), "" );
    static_assert (!sv1.starts_with('x'), "" );
    static_assert ( sv2.starts_with('a'), "" );
    static_assert (!sv2.starts_with('x'), "" );
    }
#endif

  return 0;
}
Example #16
0
int main()
{
    {
        typedef NotConstructible T;
        typedef std::forward_list<T> C;
        C c;
        ASSERT_NOEXCEPT(c.clear());
        c.clear();
        assert(distance(c.begin(), c.end()) == 0);
    }
    {
        typedef int T;
        typedef std::forward_list<T> C;
        const T t[] = {0, 1, 2, 3, 4};
        C c(std::begin(t), std::end(t));

        ASSERT_NOEXCEPT(c.clear());
        c.clear();
        assert(distance(c.begin(), c.end()) == 0);

        c.clear();
        assert(distance(c.begin(), c.end()) == 0);
    }
#if TEST_STD_VER >= 11
    {
        typedef NotConstructible T;
        typedef std::forward_list<T, min_allocator<T>> C;
        C c;
        ASSERT_NOEXCEPT(c.clear());
        c.clear();
        assert(distance(c.begin(), c.end()) == 0);
    }
    {
        typedef int T;
        typedef std::forward_list<T, min_allocator<T>> C;
        const T t[] = {0, 1, 2, 3, 4};
        C c(std::begin(t), std::end(t));

        ASSERT_NOEXCEPT(c.clear());
        c.clear();
        assert(distance(c.begin(), c.end()) == 0);

        c.clear();
        assert(distance(c.begin(), c.end()) == 0);
    }
#endif
}
Example #17
0
int main(int, char**)
{
    {
        typedef std::map<int, double> M;
        typedef std::pair<int, double> P;
        P ar[] =
        {
            P(1, 1.5),
            P(2, 2.5),
            P(3, 3.5),
            P(4, 4.5),
            P(5, 5.5),
            P(6, 6.5),
            P(7, 7.5),
            P(8, 8.5),
        };
        M m(ar, ar + sizeof(ar)/sizeof(ar[0]));
        assert(m.size() == 8);
        ASSERT_NOEXCEPT(m.clear());
        m.clear();
        assert(m.size() == 0);
    }
#if TEST_STD_VER >= 11
    {
        typedef std::map<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M;
        typedef std::pair<int, double> P;
        P ar[] =
        {
            P(1, 1.5),
            P(2, 2.5),
            P(3, 3.5),
            P(4, 4.5),
            P(5, 5.5),
            P(6, 6.5),
            P(7, 7.5),
            P(8, 8.5),
        };
        M m(ar, ar + sizeof(ar)/sizeof(ar[0]));
        assert(m.size() == 8);
        ASSERT_NOEXCEPT(m.clear());
        m.clear();
        assert(m.size() == 0);
    }
#endif

  return 0;
}
Example #18
0
void test_noexcept() {
    struct NothrowMoveable {
      NothrowMoveable() = default;
      NothrowMoveable(NothrowMoveable const&) {}
      NothrowMoveable(NothrowMoveable&&) noexcept {}
    };
    struct TestType {
      TestType(int, NothrowMoveable) noexcept {}
      TestType(int, int, int) noexcept(false) {}
      TestType(long, long, long) noexcept {}
    };
    {
        using Tuple = std::tuple<int, NothrowMoveable>;
        Tuple tup; ((void)tup);
        Tuple const& ctup = tup; ((void)ctup);
        ASSERT_NOT_NOEXCEPT(std::make_from_tuple<TestType>(ctup));
        ASSERT_NOEXCEPT(std::make_from_tuple<TestType>(std::move(tup)));
    }
    {
        using Tuple = std::pair<int, NothrowMoveable>;
        Tuple tup; ((void)tup);
        Tuple const& ctup = tup; ((void)ctup);
        ASSERT_NOT_NOEXCEPT(std::make_from_tuple<TestType>(ctup));
        ASSERT_NOEXCEPT(std::make_from_tuple<TestType>(std::move(tup)));
    }
    {
        using Tuple = std::tuple<int, int, int>;
        Tuple tup; ((void)tup);
        ASSERT_NOT_NOEXCEPT(std::make_from_tuple<TestType>(tup));
    }
    {
        using Tuple = std::tuple<long, long, long>;
        Tuple tup; ((void)tup);
        ASSERT_NOEXCEPT(std::make_from_tuple<TestType>(tup));
    }
    {
        using Tuple = std::array<int, 3>;
        Tuple tup; ((void)tup);
        ASSERT_NOT_NOEXCEPT(std::make_from_tuple<TestType>(tup));
    }
    {
        using Tuple = std::array<long, 3>;
        Tuple tup; ((void)tup);
        ASSERT_NOEXCEPT(std::make_from_tuple<TestType>(tup));
    }
}
Example #19
0
int main()
{
    using year = std::chrono::year;
    ASSERT_NOEXCEPT(++(std::declval<year&>())  );
    ASSERT_NOEXCEPT(  (std::declval<year&>())++);

    ASSERT_SAME_TYPE(year , decltype(  std::declval<year&>()++));
    ASSERT_SAME_TYPE(year&, decltype(++std::declval<year&>()  ));

    static_assert(testConstexpr<year>(), "");

    for (int i = 11000; i <= 11020; ++i)
    {
        year year(i);
        assert(static_cast<int>(++year) == i + 1);
        assert(static_cast<int>(year++) == i + 1);
        assert(static_cast<int>(year)   == i + 2);
    }
}
Example #20
0
int main()
{
    using weekday = std::chrono::weekday;
    ASSERT_NOEXCEPT(++(std::declval<weekday&>())  );
    ASSERT_NOEXCEPT(  (std::declval<weekday&>())++);

    ASSERT_SAME_TYPE(weekday , decltype(  std::declval<weekday&>()++));
    ASSERT_SAME_TYPE(weekday&, decltype(++std::declval<weekday&>()  ));

    static_assert(testConstexpr<weekday>(), "");

    for (unsigned i = 0; i <= 6; ++i)
    {
        weekday wd(i);
        assert((static_cast<unsigned>(++wd) == euclidian_addition<unsigned, 0, 6>(i, 1)));
        assert((static_cast<unsigned>(wd++) == euclidian_addition<unsigned, 0, 6>(i, 1)));
        assert((static_cast<unsigned>(wd)   == euclidian_addition<unsigned, 0, 6>(i, 2)));
    }
}
Example #21
0
int main()
{
    using year  = std::chrono::year;

    ASSERT_NOEXCEPT(+std::declval<year>());
    ASSERT_NOEXCEPT(-std::declval<year>());

    ASSERT_SAME_TYPE(year, decltype(+std::declval<year>()));
    ASSERT_SAME_TYPE(year, decltype(-std::declval<year>()));

    static_assert(testConstexpr<year>(), "");

    for (int i = 10000; i <= 10020; ++i)
    {
        year year(i);
        assert(static_cast<int>(+year) ==  i);
        assert(static_cast<int>(-year) == -i);
    }
}
Example #22
0
// can't hash nullptr_t until C++17
void test_nullptr()
{
#if TEST_STD_VER > 14
    typedef std::nullptr_t T;
    typedef std::hash<T> H;
    static_assert((std::is_same<typename H::argument_type, T>::value), "" );
    static_assert((std::is_same<typename H::result_type, std::size_t>::value), "" );
    ASSERT_NOEXCEPT(H()(T()));
#endif
}
int main(int, char**)
{
    using year                    = std::chrono::year;
    using month                   = std::chrono::month;
    using weekday                 = std::chrono::weekday;
    using weekday_last            = std::chrono::weekday_last;
    using year_month_weekday_last = std::chrono::year_month_weekday_last;
    using months                  = std::chrono::months;

    ASSERT_NOEXCEPT(std::declval<year_month_weekday_last&>() += std::declval<months>());
    ASSERT_NOEXCEPT(std::declval<year_month_weekday_last&>() -= std::declval<months>());

    ASSERT_SAME_TYPE(year_month_weekday_last&, decltype(std::declval<year_month_weekday_last&>() += std::declval<months>()));
    ASSERT_SAME_TYPE(year_month_weekday_last&, decltype(std::declval<year_month_weekday_last&>() -= std::declval<months>()));

    constexpr weekday Tuesday = std::chrono::Tuesday;
    static_assert(testConstexpr<year_month_weekday_last, months>(year_month_weekday_last{year{1234}, month{1}, weekday_last{Tuesday}}), "");

    for (unsigned i = 0; i <= 10; ++i)
    {
        year y{1234};
        year_month_weekday_last ymwd(y, month{i}, weekday_last{Tuesday});

        assert(static_cast<unsigned>((ymwd += months{2}).month()) == i + 2);
        assert(ymwd.year()     == y);
        assert(ymwd.weekday()  == Tuesday);

        assert(static_cast<unsigned>((ymwd             ).month()) == i + 2);
        assert(ymwd.year()     == y);
        assert(ymwd.weekday()  == Tuesday);

        assert(static_cast<unsigned>((ymwd -= months{1}).month()) == i + 1);
        assert(ymwd.year()     == y);
        assert(ymwd.weekday()  == Tuesday);

        assert(static_cast<unsigned>((ymwd             ).month()) == i + 1);
        assert(ymwd.year()     == y);
        assert(ymwd.weekday()  == Tuesday);
    }

  return 0;
}
Example #24
0
int main()
{
    using day = std::chrono::day;

    ASSERT_NOEXCEPT(day{});
    ASSERT_NOEXCEPT(day(0U));
    ASSERT_NOEXCEPT(static_cast<unsigned>(day(0U)));

    constexpr day d0{};
    static_assert(static_cast<unsigned>(d0) == 0, "");

    constexpr day d1{1};
    static_assert(static_cast<unsigned>(d1) == 1, "");

    for (unsigned i = 0; i <= 255; ++i)
    {
        day day(i);
        assert(static_cast<unsigned>(day) == i);
    }
}
Example #25
0
int main()
{
    typedef std::chrono::system_clock Clock;
    typedef std::chrono::milliseconds Duration;
    typedef std::chrono::time_point<Clock, Duration> TP;
	LIBCPP_ASSERT_NOEXCEPT(TP::max());
#if TEST_STD_VER > 17
	ASSERT_NOEXCEPT(       TP::max());
#endif
    assert(TP::max() == TP(Duration::max()));
}
int main()
{
    {
    typedef std::string S;
    typedef std::string_view SV;
    const char *s = "abcde";

    S   s0;
    S   s1  { s + 4, 1 };
    S   s2  { s + 3, 2 };
//  S   s3  { s + 2, 3 };
//  S   s4  { s + 1, 4 };
//  S   s5  { s,     5 };
    S  sNot { "def", 3 };

    SV  sv0;
    SV  sv1 { s + 4, 1 };
    SV  sv2 { s + 3, 2 };
    SV  sv3 { s + 2, 3 };
    SV  sv4 { s + 1, 4 };
    SV  sv5 { s    , 5 };
    SV svNot {"def", 3 };

    ASSERT_NOEXCEPT(s0.ends_with(sv0));

    assert ( s0.ends_with(sv0));
    assert (!s0.ends_with(sv1));

    assert ( s1.ends_with(sv0));
    assert ( s1.ends_with(sv1));
    assert (!s1.ends_with(sv2));
    assert (!s1.ends_with(sv3));
    assert (!s1.ends_with(sv4));
    assert (!s1.ends_with(sv5));
    assert (!s1.ends_with(svNot));

    assert ( s2.ends_with(sv0));
    assert ( s2.ends_with(sv1));
    assert ( s2.ends_with(sv2));
    assert (!s2.ends_with(sv3));
    assert (!s2.ends_with(sv4));
    assert (!s2.ends_with(sv5));
    assert (!s2.ends_with(svNot));

    assert ( sNot.ends_with(sv0));
    assert (!sNot.ends_with(sv1));
    assert (!sNot.ends_with(sv2));
    assert (!sNot.ends_with(sv3));
    assert (!sNot.ends_with(sv4));
    assert (!sNot.ends_with(sv5));
    assert ( sNot.ends_with(svNot));
    }
}
void test_get_if() {
  {
    using V = std::variant<int>;
    V *v = nullptr;
    assert(std::get_if<0>(v) == nullptr);
  }
  {
    using V = std::variant<int, long>;
    V v(42);
    ASSERT_NOEXCEPT(std::get_if<0>(&v));
    ASSERT_SAME_TYPE(decltype(std::get_if<0>(&v)), int *);
    assert(*std::get_if<0>(&v) == 42);
    assert(std::get_if<1>(&v) == nullptr);
  }
  {
    using V = std::variant<int, const long>;
    V v(42l);
    ASSERT_SAME_TYPE(decltype(std::get_if<1>(&v)), const long *);
    assert(*std::get_if<1>(&v) == 42);
    assert(std::get_if<0>(&v) == nullptr);
  }
// FIXME: Remove these once reference support is reinstated
#if !defined(TEST_VARIANT_HAS_NO_REFERENCES)
  {
    using V = std::variant<int &>;
    int x = 42;
    V v(x);
    ASSERT_SAME_TYPE(decltype(std::get_if<0>(&v)), int *);
    assert(std::get_if<0>(&v) == &x);
  }
  {
    using V = std::variant<const int &>;
    int x = 42;
    V v(x);
    ASSERT_SAME_TYPE(decltype(std::get_if<0>(&v)), const int *);
    assert(std::get_if<0>(&v) == &x);
  }
  {
    using V = std::variant<int &&>;
    int x = 42;
    V v(std::move(x));
    ASSERT_SAME_TYPE(decltype(std::get_if<0>(&v)), int *);
    assert(std::get_if<0>(&v) == &x);
  }
  {
    using V = std::variant<const int &&>;
    int x = 42;
    V v(std::move(x));
    ASSERT_SAME_TYPE(decltype(std::get_if<0>(&v)), const int *);
    assert(std::get_if<0>(&v) == &x);
  }
#endif
}
Example #28
0
int main()
{
    {
        typedef std::unordered_multiset<int> C;
        typedef int P;
        P a[] =
        {
            P(1),
            P(2),
            P(3),
            P(4),
            P(1),
            P(2)
        };
        C c(a, a + sizeof(a)/sizeof(a[0]));
        ASSERT_NOEXCEPT(c.clear());
        c.clear();
        assert(c.size() == 0);
    }
#if TEST_STD_VER >= 11
    {
        typedef std::unordered_multiset<int, std::hash<int>,
                                      std::equal_to<int>, min_allocator<int>> C;
        typedef int P;
        P a[] =
        {
            P(1),
            P(2),
            P(3),
            P(4),
            P(1),
            P(2)
        };
        C c(a, a + sizeof(a)/sizeof(a[0]));
        ASSERT_NOEXCEPT(c.clear());
        c.clear();
        assert(c.size() == 0);
    }
#endif
}
Example #29
0
int main()
{
    {
        typedef std::unordered_multimap<int, std::string> C;
        typedef std::pair<int, std::string> P;
        P a[] =
        {
            P(1, "one"),
            P(2, "two"),
            P(3, "three"),
            P(4, "four"),
            P(1, "four"),
            P(2, "four"),
        };
        C c(a, a + sizeof(a)/sizeof(a[0]));
        ASSERT_NOEXCEPT(c.clear());
        c.clear();
        assert(c.size() == 0);
    }
#if TEST_STD_VER >= 11
    {
        typedef std::unordered_multimap<int, std::string, std::hash<int>, std::equal_to<int>,
                            min_allocator<std::pair<const int, std::string>>> C;
        typedef std::pair<int, std::string> P;
        P a[] =
        {
            P(1, "one"),
            P(2, "two"),
            P(3, "three"),
            P(4, "four"),
            P(1, "four"),
            P(2, "four"),
        };
        C c(a, a + sizeof(a)/sizeof(a[0]));
        ASSERT_NOEXCEPT(c.clear());
        c.clear();
        assert(c.size() == 0);
    }
#endif
}
Example #30
0
int main() {
  using M = std::monostate;
  constexpr M m1{};
  constexpr M m2{};
  {
    static_assert((m1 < m2) == false, "");
    ASSERT_NOEXCEPT(m1 < m2);
  }
  {
    static_assert((m1 > m2) == false, "");
    ASSERT_NOEXCEPT(m1 > m2);
  }
  {
    static_assert((m1 <= m2) == true, "");
    ASSERT_NOEXCEPT(m1 <= m2);
  }
  {
    static_assert((m1 >= m2) == true, "");
    ASSERT_NOEXCEPT(m1 >= m2);
  }
  {
    static_assert((m1 == m2) == true, "");
    ASSERT_NOEXCEPT(m1 == m2);
  }
  {
    static_assert((m1 != m2) == false, "");
    ASSERT_NOEXCEPT(m1 != m2);
  }
}