PrevUpHomeNext

cpp concept: const, ref, remove, ...


c++ concept: const, ref, remove-cvref, ... - Posted on Oct 7, 2024 - See https://en.cppreference.com/w/cpp/language/constraints - Logs Home - d0034

c++

cpp concept: const, ref, remove-cvref, ...

c++ concept: const, ref, remove-cvref, ..., care.

c++ code

#include <boost/proto/proto.hpp>
#include <vector>
#include <iostream>

namespace world::space
{


template <typename type_t31>
concept additive = requires (type_t31 v0__, type_t31 v1__)
{
	#if true
	{std::forward<type_t31>(v0__) + std::forward<type_t31>(v1__)} -> std::same_as<std::remove_cvref_t<type_t31>>;
	#else
	std::forward<type_t31>(v0__) + std::forward<type_t31>(v1__);
	{std::forward<type_t31>(v0__) + std::forward<type_t31>(v1__)} -> std::same_as<std::remove_cvref_t<type_t31>>;
	#endif
};

}	// namespace world::space

int main()
{
	{
		static_assert(world::space::additive<int>);		// Satisfy
		static_assert(world::space::additive<int &>);		// Satisfy
		static_assert(world::space::additive<const int>);		// Satisfy
		static_assert(world::space::additive<const int &>);		// Satisfy

		static_assert(world::space::additive<std::string>);		// Satisfy:	std::string is additive

		static_assert(! world::space::additive<std::vector<int>>);		// std::vector does not satisfy
	}
	{
		class my_space
		{
		public:
			my_space operator+(const my_space &) const
			{
				return {};
			}
		};
		static_assert(world::space::additive<my_space>);		// Satisfy
	}
	{
		class my_space_2
		{
		public:
			const my_space_2 & operator+(const my_space_2 &) const
			{
				return *this;
			}
		};
		static_assert(! world::space::additive<my_space_2>);		// my_space_2 does not satisfy
	}
}

cpp/c++

c++ std::exception:

std::cout.write(err.data(), err.size());

std::cout << std::endl;

caught:

  ===================================
  #  The c++ programming language.  #
  #                                 #
  #  Join c++ Discord: yZcauUAUyC   #
  #  Deck                           #
  ===================================

Home: cppfx.xyz

K


PrevUpHomeNext