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));
        LIBCPP_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));
        LIBCPP_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);
        LIBCPP_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);
        LIBCPP_ASSERT_NOEXCEPT(std::make_from_tuple<TestType>(tup));
    }
}
Exemple #2
0
void test ( const CharT *s, size_t len ) {
    typedef std::basic_string_view<CharT> SV;
    SV sv ( s, len );
    ASSERT_SAME_TYPE(decltype(sv[0]), typename SV::const_reference);
    LIBCPP_ASSERT_NOEXCEPT(   sv[0]);
    assert ( sv.length() == len );
    for ( size_t i = 0; i < len; ++i ) {
        assert ( sv[i] == s[i] );
        assert ( &sv[i] == s + i );
        }
    }
Exemple #3
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()
{
    const std::shared_ptr<int> p1(new int);
    const std::shared_ptr<int> p2 = p1;
    const std::shared_ptr<int> p3(new int);
    const std::weak_ptr<int> w1(p1);
    const std::weak_ptr<int> w2(p2);
    const std::weak_ptr<int> w3(p3);
    assert(!w1.owner_before(p2));
    assert(!w2.owner_before(p1));
    assert(w1.owner_before(p3) || w3.owner_before(p1));
    assert(w3.owner_before(p1) == w3.owner_before(p2));
//  change to 'ASSERT_NOEXCEPT' when LWG2942 is adopted
    LIBCPP_ASSERT_NOEXCEPT(w1.owner_before(p2));
}
Exemple #5
0
void test()
{
	LIBCPP_ASSERT_NOEXCEPT(std::chrono::duration_values<typename D::rep>::zero());
#if TEST_STD_VER > 17
	ASSERT_NOEXCEPT(       std::chrono::duration_values<typename D::rep>::zero());
#endif
    {
    typedef typename D::rep Rep;
    Rep zero_rep = std::chrono::duration_values<Rep>::zero();
    assert(D::zero().count() == zero_rep);
    }
#if TEST_STD_VER >= 11
    {
    typedef typename D::rep Rep;
    constexpr Rep zero_rep = std::chrono::duration_values<Rep>::zero();
    static_assert(D::zero().count() == zero_rep, "");
    }
#endif
}
int main()
{
    {
    typedef std::string_view SV;
    const char *s = "abcde";
    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 };

    LIBCPP_ASSERT_NOEXCEPT(sv0.ends_with(""));

    assert ( sv0.ends_with(""));
    assert (!sv0.ends_with("e"));

    assert ( sv1.ends_with(""));
    assert ( sv1.ends_with("e"));
    assert (!sv1.ends_with("de"));
    assert (!sv1.ends_with("cde"));
    assert (!sv1.ends_with("bcde"));
    assert (!sv1.ends_with("abcde"));
    assert (!sv1.ends_with("def"));

    assert ( sv2.ends_with(""));
    assert ( sv2.ends_with("e"));
    assert ( sv2.ends_with("de"));
    assert (!sv2.ends_with("cde"));
    assert (!sv2.ends_with("bcde"));
    assert (!sv2.ends_with("abcde"));
    assert (!sv2.ends_with("def"));

    assert ( svNot.ends_with(""));
    assert (!svNot.ends_with("e"));
    assert (!svNot.ends_with("de"));
    assert (!svNot.ends_with("cde"));
    assert (!svNot.ends_with("bcde"));
    assert (!svNot.ends_with("abcde"));
    assert ( svNot.ends_with("def"));
    }

#if TEST_STD_VER > 11
    {
    typedef std::basic_string_view<char, constexpr_char_traits<char>> SV;
    constexpr const char *s = "abcde";
    constexpr SV  sv0 {};
    constexpr SV  sv1 { s + 4, 1 };
    constexpr SV  sv2 { s + 3, 2 };
//     constexpr SV  sv3 { s + 2, 3 };
//     constexpr SV  sv4 { s + 1, 4 };
//     constexpr SV  sv5 { s,     5 };
    constexpr SV  svNot {"def", 3 };

    static_assert ( sv0.ends_with(""), "" );
    static_assert (!sv0.ends_with("e"), "" );

    static_assert ( sv1.ends_with(""), "" );
    static_assert ( sv1.ends_with("e"), "" );
    static_assert (!sv1.ends_with("de"), "" );
    static_assert (!sv1.ends_with("cde"), "" );
    static_assert (!sv1.ends_with("bcde"), "" );
    static_assert (!sv1.ends_with("abcde"), "" );
    static_assert (!sv1.ends_with("def"), "" );

    static_assert ( sv2.ends_with(""), "" );
    static_assert ( sv2.ends_with("e"), "" );
    static_assert ( sv2.ends_with("de"), "" );
    static_assert (!sv2.ends_with("cde"), "" );
    static_assert (!sv2.ends_with("bcde"), "" );
    static_assert (!sv2.ends_with("abcde"), "" );
    static_assert (!sv2.ends_with("def"), "" );

    static_assert ( svNot.ends_with(""), "" );
    static_assert (!svNot.ends_with("e"), "" );
    static_assert (!svNot.ends_with("de"), "" );
    static_assert (!svNot.ends_with("cde"), "" );
    static_assert (!svNot.ends_with("bcde"), "" );
    static_assert (!svNot.ends_with("abcde"), "" );
    static_assert ( svNot.ends_with("def"), "" );
    }
#endif
}