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

FreeBSD Manual Pages

  
 
  

home | help
std::chrono::duration::max(3) C++ Standard Libarystd::chrono::duration::max(3)

NAME
       std::chrono::duration::max - std::chrono::duration::max

Synopsis
	  static constexpr duration max();	     (until C++20)
	  static constexpr duration max() noexcept;  (since C++20)

	  Returns a duration with the largest possible value.

	  If the representation	rep of the duration requires some other	imple-
       mentation to
	  return  a  maximum-length duration, std::chrono::duration_values can
       be specialized to
	  return the desired value.

Parameters
	  (none)

Return value
	  returns duration(std::chrono::duration_values<rep>::max())

Example
       // Run this code

	#include <chrono>
	#include <iostream>
	#include <iomanip>
	#include <cstdint>

	int main()
	{
	    constexpr	       uint64_t		  chrono_years_max	     =
       std::chrono::years::max().count();
	    constexpr	 uint64_t   chrono_seconds_max	 =   std::chrono::sec-
       onds::max().count();

	    constexpr uint64_t	age_of_universe_in_years{13'787'000'000};  //:
       CDM  k/H	= k/42.
	    constexpr  uint64_t	seconds_per_year{365'25	* 24 * 36}; // 365  24
       60  60
	    constexpr	  uint64_t	age_of_universe_in_seconds{age_of_uni-
       verse_in_years *	seconds_per_year};

	    std::cout
		<< "The	Age of the Universe is	"
		<< std::scientific << std::setprecision(2)
		<< static_cast<double>(age_of_universe_in_years) << " years or
       "
		<<  static_cast<double>(age_of_universe_in_seconds)  <<	" sec-
       onds.\n\n"
		<<  "chrono::years::max()  =  "	 <<  chrono_years_max  <<   ",
       sizeof(chrono::years) = "
		<< sizeof(std::chrono::years) << " bytes.\n" "chrono::years "
		<<  (age_of_universe_in_years  <=  chrono_years_max  ? "CAN" :
       "CANNOT")
		<< " keep the Age of the Universe in YEARS.\n\n"
		<< "chrono::seconds::max() = "	<<  chrono_seconds_max	<<  ",
       sizeof(chrono::seconds) = "
		<<  sizeof(std::chrono::seconds)  << " bytes.\n" "chrono::sec-
       onds "
		<< (age_of_universe_in_seconds <= chrono_seconds_max ? "CAN" :
       "CANNOT")
		<< " keep the Age of the Universe in SECONDS.\n";
	}

Possible output:
	The Age	of the Universe	is  1.38e+10 years or 4.35e+17 seconds.

	chrono::years::max() = 2147483647, sizeof(chrono::years) = 4 bytes.
	chrono::years CANNOT keep the Age of the Universe in YEARS.

	chrono::seconds::max() = 9223372036854775807,  sizeof(chrono::seconds)
       = 8 bytes.
	chrono::seconds	CAN keep the Age of the	Universe in SECONDS.

See also
	  zero	   returns the special duration	value zero
	  [static] (public static member function)
	  min	   returns the special duration	value min
	  [static] (public static member function)

http://cppreference.com		  2022.07.31	 std::chrono::duration::max(3)

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

home | help