vendredi 6 septembre 2019

What is the implementation of std::min() that has a single parameter?

I saw the following statement in a code (should I provide the complete code?):

std::min(0);

The closest definition I can find is:

template <class T> constexpr T min (initializer_list<T> il);

So far I found the implementation in stl_algo.h:

template<typename _Tp>
    _GLIBCXX14_CONSTEXPR
    inline _Tp
    min(initializer_list<_Tp> __l)
    { return *std::min_element(__l.begin(), __l.end()); }

I used to think that std::min() only calculates the minimum of two items. Can anyone explain to me what does it actually do? And what is an initializer_list?

Aucun commentaire:

Enregistrer un commentaire