示例#1
0
文件: internal.hpp 项目: Kitware/VTK
 static bool match( Input& in ) noexcept( noexcept( Peek::peek( in ) ) )
 {
    if( const auto r = Peek::peek( in ) ) {
       if( u_getIntPropertyValue( r.data, P ) == V ) {
          in.bump( r.size );
          return true;
       }
    }
    return false;
 }
示例#2
0
inline auto member_delegate(C& object,
  R (C::* const)(A...) volatile) noexcept
{
  return [&object](A&& ...args) noexcept(
      noexcept((object.*fp)(::std::forward<A>(args)...))
    )
    {
      return (object.*fp)(::std::forward<A>(args)...);
    };
}
示例#3
0
		const CharType *c_str() const noexcept(noexcept(CharType(0)))
		{
			if (m_buf == nullptr) {
				return empty;
			} else {
				// Terminating the string with the null character.
				*m_bufEnd = CharType(0);
				return m_buf;
			}
		}
示例#4
0
inline auto member_delegate(C* const object,
  R (C::* const)(A...) const) noexcept
{
  return [object](A&& ...args) noexcept(
      noexcept((object->*fp)(::std::forward<A>(args)...))
    )
    {
      return (object->*fp)(::std::forward<A>(args)...);
    };
}
示例#5
0
int main()
{
#if __has_feature(cxx_noexcept)
    {
        typedef std::string C;
        C c1, c2;
        static_assert(noexcept(swap(c1, c2)), "");
    }
    {
        typedef std::basic_string<char, std::char_traits<char>, test_allocator<char>> C;
        C c1, c2;
        static_assert(noexcept(swap(c1, c2)), "");
    }
    {
        typedef std::basic_string<char, std::char_traits<char>, some_alloc<char>> C;
        C c1, c2;
        static_assert(!noexcept(swap(c1, c2)), "");
    }
#endif
}
示例#6
0
int main()
{
#if _LIBCPP_STD_VER > 11
    {
    typedef int T;
    typedef std::optional<T> O;
    
    constexpr O o1;     // disengaged
    constexpr O o2{1};  // engaged

    static_assert (   std::nullopt == o1 , "" );
    static_assert ( !(std::nullopt == o2), "" );
    static_assert (   o1 == std::nullopt , "" );
    static_assert ( !(o2 == std::nullopt), "" );

    static_assert (noexcept(std::nullopt == o1), "");
    static_assert (noexcept(o1 == std::nullopt), "");
    }
#endif
}
示例#7
0
int main () {
    constexpr std::byte b1{static_cast<std::byte>(1)};
    constexpr std::byte b3{static_cast<std::byte>(3)};

    static_assert(noexcept(b3 << 2), "" );

    static_assert(std::to_integer<int>(b1 << 1) ==   2, "");
    static_assert(std::to_integer<int>(b1 << 2) ==   4, "");
    static_assert(std::to_integer<int>(b3 << 4) ==  48, "");
    static_assert(std::to_integer<int>(b3 << 6) == 192, "");
}
示例#8
0
 static eol_pair match( Input& in ) noexcept( noexcept( in.size( 1 ) ) )
 {
    eol_pair p = { false, in.size( 1 ) };
    if( p.second ) {
       if( in.peek_char() == '\r' ) {
          in.bump_to_next_line();
          p.first = true;
       }
    }
    return p;
 }
namespace sad {
  template<typename T> void swap(T &, T &);

  template<typename A, typename B> struct pair {
    void swap(pair &other) noexcept(noexcept(swap(*this, other))); // expected-error {{too many arguments}} expected-note {{declared here}}
  };

  pair<int, int> pi;

  static_assert(!noexcept(pi.swap(pi)), ""); // expected-note {{in instantiation of}}
}
示例#10
0
            VRM_CORE_ALWAYS_INLINE constexpr static void exec(
                TF&& f, Ts&&... xs) noexcept(noexcept(IMPL_FORNARGS_BODY()))
            {
                VRM_CORE_STATIC_ASSERT(
                    TArity > 0, "Unallowed arity: must be greater than 0");

                VRM_CORE_STATIC_ASSERT(sizeof...(Ts) % TArity == 0,
                    "Unallowed arity: not divisible by number of arguments");

                IMPL_FORNARGS_BODY();
            }
示例#11
0
R invoke_5f_(int, cradle::identity<R>, F &&f, Args &&... args)
  noexcept(
    noexcept(
      std::forward<F>(f)(std::forward<Args>(args)...))
    && std::is_nothrow_constructible<
         R,
         decltype(
           (std::forward<F>(f)(std::forward<Args>(args)...)))>::value)
{
  return std::forward<F>(f)(std::forward<Args>(args)...);
}
int main(int, char**)
{
  using H = coro::coroutine_handle<>;
  using S = SuspendT;
  H h{};
  S s{};
  S const& cs = s;
  {
    LIBCPP_STATIC_ASSERT(noexcept(s.await_ready()), "");
    static_assert(std::is_same<decltype(s.await_ready()), bool>::value, "");
    assert(s.await_ready() == false);
    assert(cs.await_ready() == false);
  }
  {
    LIBCPP_STATIC_ASSERT(noexcept(s.await_suspend(h)), "");
    static_assert(std::is_same<decltype(s.await_suspend(h)), void>::value, "");
    s.await_suspend(h);
    cs.await_suspend(h);
  }
  {
    LIBCPP_STATIC_ASSERT(noexcept(s.await_resume()), "");
    static_assert(std::is_same<decltype(s.await_resume()), void>::value, "");
    s.await_resume();
    cs.await_resume();
  }
  {
    static_assert(std::is_nothrow_default_constructible<S>::value, "");
    static_assert(std::is_nothrow_copy_constructible<S>::value, "");
    static_assert(std::is_nothrow_move_constructible<S>::value, "");
    static_assert(std::is_nothrow_copy_assignable<S>::value, "");
    static_assert(std::is_nothrow_move_assignable<S>::value, "");
    static_assert(std::is_trivially_copyable<S>::value, "");
    static_assert(check_suspend_constexpr(), "");
  }
  {
    // suppress unused warnings for the global constexpr test variable
    ((void)constexpr_sa);
  }

  return 0;
}
示例#13
0
int main(int, char**)
{
    std::shared_lock<std::shared_timed_mutex> lk0;
    assert(lk0.mutex() == nullptr);
    std::shared_lock<std::shared_timed_mutex> lk1(m);
    assert(lk1.mutex() == &m);
    lk1.unlock();
    assert(lk1.mutex() == &m);
    static_assert(noexcept(lk0.mutex()), "mutex() must be noexcept");

  return 0;
}
示例#14
0
		type::bool_t synchronize(Functor && functor) noexcept(noexcept(functor()))
		{
			thread_local auto & atomic = entity_lock<Current>::get_state();

			auto & thread_state = detail::thread_lock_state<Current>();

			if (thread_state)
			{
				if (synchronize<Next, Rest ... >(std::forward<Functor>(functor)))
				{
					return true;
				} return false;
			}

			if (atomic.exchange(true))
			{
				return false;
			}

			else

			{
				thread_state = true;

				try
				{
					if (synchronize<Next, Rest ... >(std::forward<Functor>(functor)))
					{
						thread_state = false;
						atomic.store(false, std::memory_order_release);

						return true;
					}

					else

					{
						thread_state = false;
						atomic.store(false, std::memory_order_release);

						return false;
					}
				}

				catch (...)
				{
					thread_state = false;
					atomic.store(false, std::memory_order_release);

					throw;
				}
			}
		}
void
test0()
{
#if TEST_STD_VER > 14
    static_assert((noexcept(C{})), "" );
#elif TEST_STD_VER >= 11
    static_assert((noexcept(C()) == noexcept(typename C::allocator_type())), "" );
#endif
    C c;
    LIBCPP_ASSERT(c.__invariants());
    assert(c.empty());
    assert(c.get_allocator() == typename C::allocator_type());
    LIBCPP_ASSERT(is_contiguous_container_asan_correct(c));
#if TEST_STD_VER >= 11
    C c1 = {};
    LIBCPP_ASSERT(c1.__invariants());
    assert(c1.empty());
    assert(c1.get_allocator() == typename C::allocator_type());
    LIBCPP_ASSERT(is_contiguous_container_asan_correct(c1));
#endif
}
示例#16
0
 namespace equality {
     struct tag {};
     template <typename T0, typename T1,
               typename = nstd::type_traits::enable_if_t<
                   nstd::type_traits::is_convertible<nstd::type_traits::decay_t<T0>*, nstd::operators::equality::tag*>::value
                   && nstd::type_traits::is_convertible<nstd::type_traits::decay_t<T1>*, nstd::operators::equality::tag*>::value
                >
               >
     constexpr auto operator!= (T0&& value0, T1&& value1)
         noexcept(noexcept(bool(value0 == value1)))
         -> bool;
 }
示例#17
0
Pair<NumeratorT_, DenominatorT_> constexpr normalize_(
	Pair<NumeratorT_, DenominatorT_> const& pair_,
	CommonType<NumeratorT_, DenominatorT_> workaround__ = CommonType<NumeratorT_, DenominatorT_>()
) noexcept(noexcept(
	workaround__ = greatest_common_divisor<CommonType<NumeratorT_, DenominatorT_>>(pair_.first, pair_.second),
	Pair<NumeratorT_, DenominatorT_>(pair_.first / workaround__, pair_.second / workaround__)
)) {
	return
		workaround__ = greatest_common_divisor<CommonType<NumeratorT_, DenominatorT_>>(pair_.first, pair_.second),
		Pair<NumeratorT_, DenominatorT_>(pair_.first / workaround__, pair_.second / workaround__)
	;
}
示例#18
0
namespace sad {
  template<typename T> void swap(T &, T &);

  template<typename A, typename B> struct CLASS {
    void swap(CLASS &other) noexcept(noexcept(swap(*this, other))); // expected-error {{too many arguments}} expected-note {{declared here}}
    // expected-error@-1{{uses itself}} expected-note@-1{{in instantiation of}}
  };

  CLASS<int, int> pi;

  static_assert(!noexcept(pi.swap(pi)), ""); // expected-note 2{{in instantiation of exception specification for 'swap'}}
}
示例#19
0
int main()
{
#if _LIBCPP_STD_VER > 11
    std::shared_lock<std::shared_timed_mutex> lk0;
    assert(lk0.owns_lock() == false);
    std::shared_lock<std::shared_timed_mutex> lk1(m);
    assert(lk1.owns_lock() == true);
    lk1.unlock();
    assert(lk1.owns_lock() == false);
    static_assert(noexcept(lk0.owns_lock()), "owns_lock must be noexcept");
#endif  // _LIBCPP_STD_VER > 11
}
示例#20
0
int main(int, char**)
{
    {
        typedef int T;
        std::promise<T> p;
        std::shared_future<T> f0 = p.get_future();
        std::shared_future<T> f = f0;
#if TEST_STD_VER > 14
        static_assert(noexcept(std::shared_future<T>{f0}), "" );
#endif
        assert(f0.valid());
        assert(f.valid());
    }
    {
        typedef int T;
        std::shared_future<T> f0;
        std::shared_future<T> f = f0;
        assert(!f0.valid());
        assert(!f.valid());
    }
    {
        typedef int& T;
        std::promise<T> p;
        std::shared_future<T> f0 = p.get_future();
        std::shared_future<T> f = f0;
        assert(f0.valid());
        assert(f.valid());
    }
    {
        typedef int& T;
        std::shared_future<T> f0;
        std::shared_future<T> f = std::move(f0);
        assert(!f0.valid());
        assert(!f.valid());
    }
    {
        typedef void T;
        std::promise<T> p;
        std::shared_future<T> f0 = p.get_future();
        std::shared_future<T> f = f0;
        assert(f0.valid());
        assert(f.valid());
    }
    {
        typedef void T;
        std::shared_future<T> f0;
        std::shared_future<T> f = f0;
        assert(!f0.valid());
        assert(!f.valid());
    }

  return 0;
}
示例#21
0
int main(int, char**)
{
    {
    typedef std::tuple<int> T;
    const T t(3);
    static_assert(std::is_same<const int&&, decltype(std::get<0>(std::move(t)))>::value, "");
    static_assert(noexcept(std::get<0>(std::move(t))), "");
    const int&& i = std::get<0>(std::move(t));
    assert(i == 3);
    }

    {
    typedef std::tuple<std::string, int> T;
    const T t("high", 5);
    static_assert(std::is_same<const std::string&&, decltype(std::get<0>(std::move(t)))>::value, "");
    static_assert(noexcept(std::get<0>(std::move(t))), "");
    static_assert(std::is_same<const int&&, decltype(std::get<1>(std::move(t)))>::value, "");
    static_assert(noexcept(std::get<1>(std::move(t))), "");
    const std::string&& s = std::get<0>(std::move(t));
    const int&& i = std::get<1>(std::move(t));
    assert(s == "high");
    assert(i == 5);
    }

    {
    int x = 42;
    int const y = 43;
    std::tuple<int&, int const&> const p(x, y);
    static_assert(std::is_same<int&, decltype(std::get<0>(std::move(p)))>::value, "");
    static_assert(noexcept(std::get<0>(std::move(p))), "");
    static_assert(std::is_same<int const&, decltype(std::get<1>(std::move(p)))>::value, "");
    static_assert(noexcept(std::get<1>(std::move(p))), "");
    }

    {
    int x = 42;
    int const y = 43;
    std::tuple<int&&, int const&&> const p(std::move(x), std::move(y));
    static_assert(std::is_same<int&&, decltype(std::get<0>(std::move(p)))>::value, "");
    static_assert(noexcept(std::get<0>(std::move(p))), "");
    static_assert(std::is_same<int const&&, decltype(std::get<1>(std::move(p)))>::value, "");
    static_assert(noexcept(std::get<1>(std::move(p))), "");
    }

#if TEST_STD_VER > 11
    {
    typedef std::tuple<double, int> T;
    constexpr const T t(2.718, 5);
    static_assert(std::get<0>(std::move(t)) == 2.718, "");
    static_assert(std::get<1>(std::move(t)) == 5, "");
    }
#endif

  return 0;
}
示例#22
0
int main()
{
    {
        typedef std::vector<MoveOnly> C;
        static_assert(noexcept(swap(std::declval<C&>(), std::declval<C&>())), "");
    }
    {
        typedef std::vector<MoveOnly, test_allocator<MoveOnly>> C;
        LIBCPP_STATIC_ASSERT(noexcept(swap(std::declval<C&>(), std::declval<C&>())), "");
    }
    {
        typedef std::vector<MoveOnly, other_allocator<MoveOnly>> C;
        static_assert(noexcept(swap(std::declval<C&>(), std::declval<C&>())), "");
    }
    {
        typedef std::vector<MoveOnly, some_alloc<MoveOnly>> C;
#if TEST_STD_VER >= 14
    //  In c++14, if POCS is set, swapping the allocator is required not to throw
        static_assert( noexcept(swap(std::declval<C&>(), std::declval<C&>())), "");
#else
        static_assert(!noexcept(swap(std::declval<C&>(), std::declval<C&>())), "");
#endif
    }
#if TEST_STD_VER >= 14
    {
        typedef std::vector<MoveOnly, some_alloc2<MoveOnly>> C;
    //  if the allocators are always equal, then the swap can be noexcept
        static_assert( noexcept(swap(std::declval<C&>(), std::declval<C&>())), "");
    }
#endif
}
示例#23
0
int main()
{
    // check return types
    {
        ex::memory_resource const * mr1(nullptr);
        ex::memory_resource const * mr2(nullptr);
        static_assert(std::is_same<decltype(*mr1 == *mr2), bool>::value, "");
        static_assert(noexcept(*mr1 == *mr2), "");
    }
    // equal
    {
        TestResource r1(1);
        TestResource r2(1);
        ex::memory_resource const & mr1 = r1;
        ex::memory_resource const & mr2 = r2;

        assert(mr1 == mr2);
        assert(r1.checkIsEqualCalledEq(1));
        assert(r2.checkIsEqualCalledEq(0));

        assert(mr2 == mr1);
        assert(r1.checkIsEqualCalledEq(1));
        assert(r2.checkIsEqualCalledEq(1));
    }
    // equal same object
    {
        TestResource r1(1);
        ex::memory_resource const & mr1 = r1;
        ex::memory_resource const & mr2 = r1;

        assert(mr1 == mr2);
        assert(r1.checkIsEqualCalledEq(0));

        assert(mr2 == mr1);
        assert(r1.checkIsEqualCalledEq(0));
    }
    // not equal
    {
        TestResource r1(1);
        TestResource r2(2);
        ex::memory_resource const & mr1 = r1;
        ex::memory_resource const & mr2 = r2;

        assert(!(mr1 == mr2));
        assert(r1.checkIsEqualCalledEq(1));
        assert(r2.checkIsEqualCalledEq(0));

        assert(!(mr2 == mr1));
        assert(r1.checkIsEqualCalledEq(1));
        assert(r2.checkIsEqualCalledEq(1));
    }
}
示例#24
0
int main(int, char**) {
    constexpr std::byte b1{static_cast<std::byte>(1)};
    constexpr std::byte b2{static_cast<std::byte>(2)};
    constexpr std::byte b8{static_cast<std::byte>(8)};

    static_assert(noexcept(~b1), "" );

    static_assert(std::to_integer<int>(~b1) == 254, "");
    static_assert(std::to_integer<int>(~b2) == 253, "");
    static_assert(std::to_integer<int>(~b8) == 247, "");

  return 0;
}
示例#25
0
int main()
{
    typedef std::pair<const MoveOnly, MoveOnly> V;
    {
        typedef std::multimap<MoveOnly, MoveOnly> C;
        static_assert(noexcept(swap(std::declval<C&>(), std::declval<C&>())), "");
    }
    {
        typedef std::multimap<MoveOnly, MoveOnly, std::less<MoveOnly>, test_allocator<V>> C;
        LIBCPP_STATIC_ASSERT(noexcept(swap(std::declval<C&>(), std::declval<C&>())), "");
    }
    {
        typedef std::multimap<MoveOnly, MoveOnly, std::less<MoveOnly>, other_allocator<V>> C;
        LIBCPP_STATIC_ASSERT(noexcept(swap(std::declval<C&>(), std::declval<C&>())), "");
    }
    {
        typedef std::multimap<MoveOnly, MoveOnly, some_comp<MoveOnly>> C;
        static_assert(!noexcept(swap(std::declval<C&>(), std::declval<C&>())), "");
    }

#if TEST_STD_VER >= 14
    { // POCS allocator, throwable swap for comp
    typedef std::multimap<MoveOnly, MoveOnly, some_comp <MoveOnly>, some_alloc <V>> C;
    static_assert(!noexcept(swap(std::declval<C&>(), std::declval<C&>())), "");
    }
    { // always equal allocator, throwable swap for comp
    typedef std::multimap<MoveOnly, MoveOnly, some_comp <MoveOnly>, some_alloc2<V>> C;
    static_assert(!noexcept(swap(std::declval<C&>(), std::declval<C&>())), "");
    }
    { // POCS allocator, nothrow swap for comp
    typedef std::multimap<MoveOnly, MoveOnly, some_comp2<MoveOnly>, some_alloc <V>> C;
    static_assert( noexcept(swap(std::declval<C&>(), std::declval<C&>())), "");
    }
    { // always equal allocator, nothrow swap for comp
    typedef std::multimap<MoveOnly, MoveOnly, some_comp2<MoveOnly>, some_alloc2<V>> C;
    static_assert( noexcept(swap(std::declval<C&>(), std::declval<C&>())), "");
    }

    { // NOT always equal allocator, nothrow swap for comp
    typedef std::multimap<MoveOnly, MoveOnly, some_comp2<MoveOnly>, some_alloc3<V>> C;
    LIBCPP_STATIC_ASSERT( noexcept(swap(std::declval<C&>(), std::declval<C&>())), "");
    }
#endif
}
示例#26
0
文件: p14.cpp 项目: Godin/clang
namespace PR13381 {
  struct NoThrowMove {
    NoThrowMove(const NoThrowMove &);
    NoThrowMove(NoThrowMove &&) noexcept;
    NoThrowMove &operator=(const NoThrowMove &);
    NoThrowMove &operator=(NoThrowMove &&) noexcept;
  };
  struct NoThrowMoveOnly {
    NoThrowMoveOnly(NoThrowMoveOnly &&) noexcept;
    NoThrowMoveOnly &operator=(NoThrowMoveOnly &&) noexcept;
  };
  struct X {
    const NoThrowMove a;
    NoThrowMoveOnly b;

    static X val();
    static X &ref();
  };
  // These both perform a move, but that copy might throw, because it calls
  // NoThrowMove's copy constructor (because PR13381::a is const).
  static_assert(!noexcept(X(X::val())), "");
  static_assert(!noexcept(X::ref() = X::val()), "");
}
示例#27
0
 transform_iterator<
   typename std::remove_reference<Adapter>::type,
   typename std::remove_reference<Iterator>::type>
 make_transform_iterator(Adapter &&adapter, Iterator &&iter)
 noexcept(noexcept(transform_iterator<
   typename std::remove_reference<Adapter>::type,
   typename std::remove_reference<Iterator>::type>(
     std::forward<Adapter>(adapter), std::forward<Iterator>(iter))))
 {
   return transform_iterator<
   typename std::remove_reference<Adapter>::type,
   typename std::remove_reference<Iterator>::type>(
     std::forward<Adapter>(adapter), std::forward<Iterator>(iter));
 }
示例#28
0
int main(int, char**)
{
    {
        typedef double T;
        typedef std::array<T, 3> C;
        C c1 = {1, 2, 3.5};
        C c2 = {4, 5, 6.5};
        swap(c1, c2);
        assert(c1.size() == 3);
        assert(c1[0] == 4);
        assert(c1[1] == 5);
        assert(c1[2] == 6.5);
        assert(c2.size() == 3);
        assert(c2[0] == 1);
        assert(c2[1] == 2);
        assert(c2[2] == 3.5);
    }
    {
        typedef double T;
        typedef std::array<T, 0> C;
        C c1 = {};
        C c2 = {};
        swap(c1, c2);
        assert(c1.size() == 0);
        assert(c2.size() == 0);
    }
    {
        typedef NonSwappable T;
        typedef std::array<T, 0> C0;
        static_assert(can_swap<C0&>::value, "");
        C0 l = {};
        C0 r = {};
        swap(l, r);
#if TEST_STD_VER >= 11
        static_assert(noexcept(swap(l, r)), "");
#endif
    }
#if TEST_STD_VER >= 11
    {
        // NonSwappable is still considered swappable in C++03 because there
        // is no access control SFINAE.
        typedef NonSwappable T;
        typedef std::array<T, 42> C1;
        static_assert(!can_swap<C1&>::value, "");
    }
#endif

  return 0;
}
示例#29
0
文件: point.hpp 项目: RobertLeahy/MST
			std::size_t operator () (const Point<T> & p) const noexcept(
				noexcept(hasher{}(p.X))
			) {
			
				std::size_t retr=23;
				
				hasher h;
				retr*=31;
				retr+=h(p.X);
				retr*=31;
				retr+=h(p.Y);
				
				return retr;
			
			}
示例#30
0
void test() {
  X foo;

  try {
  } catch (X e) {
    X x;
  }

  struct LocalS {
    void meth() {
      int x;
      ++x;
    }
  };
}