Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages

  
 
  

home | help
std::derived_from(3)	      C++ Standard Libary	  std::derived_from(3)

NAME
       std::derived_from - std::derived_from

Synopsis
	  Defined in header <concepts>
	  template< class Derived, class Base >

	  concept derived_from =
	      std::is_base_of_v<Base,		     Derived>		    &&
       (since C++20)

	      std::is_convertible_v<const volatile Derived*, const volatile
	  Base*>;

	  The concept derived_from<Derived, Base> is satisfied if and only  if
       Base is a class
	  type	that is	either Derived or a public and unambiguous base	of De-
       rived, ignoring
	  cv-qualifiers.

	  Note that this behavior is different to std::is_base_of when Base is
       a private or
	  protected base of Derived.

Example
       // Run this code

	#include <concepts>

	class A	{};

	class B	: public A {};

	class C	: private A {};

	// std::derived_from ==	true only for public inheritance or exact same
       class
	static_assert(std::derived_from<B, B> == true);	      //  same	class:
       true
	static_assert(std::derived_from<int, int> == false); //	same primitive
       type: false
	static_assert(std::derived_from<B, A> == true);	     //	public inheri-
       tance: true
	static_assert(std::derived_from<C, A> == false);     //	private	inher-
       itance: false

	// std::is_base_of == true also	for private inheritance
	static_assert(std::is_base_of_v<B,  B>	==  true);	// same	class:
       true
	static_assert(std::is_base_of_v<int, int> == false); //	same primitive
       type: false
	static_assert(std::is_base_of_v<A, B> == true);	     //	public inheri-
       tance: true
	static_assert(std::is_base_of_v<A, C> == true);	     //	private	inher-
       itance: true

	int main() {}

See also
	  is_base_of		 checks	if a type is derived  from  the	 other
       type
	  (C++11)		 (class	template)
	  is_convertible
	  is_nothrow_convertible  checks  if  a	 type  can be converted	to the
       other type
	  (C++11)		 (class	template)
	  (C++20)

http://cppreference.com		  2024.06.10		  std::derived_from(3)

Want to link to this manual page? Use this URL:
<https://man.freebsd.org/cgi/man.cgi?query=std::derived_from&sektion=3&manpath=FreeBSD+Ports+15.1.quarterly>

home | help