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

FreeBSD Manual Pages

  
 
  

home | help
std::ranges...n_max_result(3) C++ Standard Libarystd::ranges...n_max_result(3)

NAME
       std::ranges::min_max_result - std::ranges::min_max_result

Synopsis
	  Defined in header <algorithm>
	  template< class T >		 (since	C++20)
	  struct min_max_result;

	  ranges::min_max_result  is  a	 class template	that provides a	way to
       store two objects
	  or references	of the same type as a single unit.

	  This class template has no base classes or  declared	members	 other
       than those shown
	  below. Thus it is suitable for use with structured bindings.

	  All  special	member functions of this class template	are implicitly
       declared, which
	  makes	specializations	be aggregate classes, and  propagate  trivial-
       ity,
	  potentially-throwing-ness, and constexpr-ness	of corresponding oper-
       ations on data
	  members.

Template parameters
	  T   -	  the	type   of   the	  objects   or	 references  that  the
       ranges::min_max_result stores.

	  Data members

	  Member name Definition
		      may be a reference to, a copy of,	or an iterator of type
       T to a minimum
	  min	      element in a range.
		      (public member object)
		      may be a reference to, a copy of,	or an iterator of type
       T to a maximum
	  max	      element in a range
		      (public member object)

	  All these members are	declared with [[no_unique_address]] attribute.

Member functions
       std::ranges::min_max_result::operator min_max_result<T2>

	  template<class T2>

	  requires std::convertible_to<const T&, T2>	   (1)

	  constexpr operator min_max_result<T2>() const	&;
	  template<class T2>

	  requires std::convertible_to<T, T2>		   (2)

	  constexpr operator min_max_result<T2>() &&;

	  Converts *this to the	result by constructing every  data  member  of
       the result from
	  the corresponding member of *this.

	  1) Equivalent	to return {min,	max};.
	  2) Equivalent	to return {std::move(min), std::move(max)};.

Standard library
	  The  following standard library functions use	ranges::min_max_result
       as the return
	  type:

		Algorithm functions
	  ranges::minmax	 returns the smaller and larger	 of  two  ele-
       ments
	  (C++20)		 (niebloid)
	  ranges::minmax_element returns the smallest and the largest elements
       in a range
	  (C++20)		 (niebloid)

Synopsis
	namespace std::ranges
	{
	    template<class T>
	    struct min_max_result
	    {
		[[no_unique_address]] T	min;
		[[no_unique_address]] T	max;

		template<class T2>
		requires std::convertible_to<const T&, T2>
		constexpr operator min_max_result<T2>()	const &
		{
		    return {min, max};
		}

		template<class T2>
		requires std::convertible_to<T,	T2>
		constexpr operator min_max_result<T2>()	&&
		{
		    return {std::move(min), std::move(max)};
		}
	    };
	}

Notes
	  Each	standard  library  algorithm  that  uses this family of	return
       types declares a	new
	  alias	type, e.g. using merge_result =	in_in_out_result<I1, I2, O>;.

	  The names for	such aliases are formed	by adding the suffix "_result"
       to the
	  algorithm's name. So,	the return type	of std::ranges::merge  can  be
       named as
	  std::ranges::merge_result.

	  Unlike  std::pair  and std::tuple, this class	template has data mem-
       bers of meaningful
	  names.

Example
       // Run this code

	#include <algorithm>
	#include <ranges>

	int main()
	{
	    constexpr static auto v = {3, 1, 4,	1, 5, 9, 2};
	    {
		constexpr auto result =	std::ranges::minmax(v);
		static_assert(1	== result.min && 9 == result.max);
	    }
	    {
		constexpr auto result =	std::ranges::minmax_element(v);
		static_assert(1	== *result.min && 9 == *result.max);
	    }
	}

See also
	  pair	  implements binary tuple, i.e.	a pair of values
		  (class template)
	  tuple	  implements fixed size	container,  which  holds  elements  of
       possibly	different
	  (C++11) types
		  (class template)

http://cppreference.com		  2024.06.10	 std::ranges...n_max_result(3)

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

home | help