Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Namespaces | Functions
minmax_transformed_element.h File Reference

Return the minimum or maximum element from a transformed range. More...

#include <ranges>
#include <utility>
#include <cstdlib>
Include dependency graph for minmax_transformed_element.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

 CxxUtils
 

Functions

template<class RANGE , class FUNC >
auto CxxUtils::min_transformed_element (RANGE &&r, FUNC &&f)
 Find the minimum transformed element in a range. More...
 
template<class RANGE , class FUNC >
auto CxxUtils::max_transformed_element (RANGE &&r, FUNC &&f)
 Find the maximum transformed element in a range. More...
 

Detailed Description

Return the minimum or maximum element from a transformed range.

Author
scott snyder snyde.nosp@m.r@bn.nosp@m.l.gov
Date
Feb, 2025 These are like std::ranges::min_element and std::ranges::max_element, except that we apply a transform to the input range first. An example would be to take a range of vectors and find the one closest to some other vector. Why not just use std::ranges::min_element along with std::ranges::transform? First, it's a bit awkward without the enumerate/zip views from C++23. But more importantly, it's hard to avoid having the transform evaluated multiple times per element. This way, the transform is evaluated exactly once per element.

Definition in file minmax_transformed_element.h.