able  ](http://en.cppreference.com/w/cpp/concepts/invocable) < const  __size_fn  & , Args...  > .   

Otherwise, no function call operator of ` ___size_fn_ ` participates in
overload resolution.

###  [ [ edit ](/mwiki/index.php?title=cpp/ranges/size&action=edit&section=1
"Edit section: Notes") ]  Notes

Whenever  ranges  ::  size  (  e  )  is valid for an expression  e  , the
return type is integer-like.

The C++20 standard requires that if the underlying ` size ` function call
returns a prvalue, the return value is move-constructed from the materialized
temporary object. All implementations directly return the prvalue instead. The
requirement is corrected by the post-C++20 proposal [ P0849R8
](https://wg21.link/P0849R8) to match the implementations.

The expression  [ ranges::  distance
](http://en.cppreference.com/w/cpp/iterator/ranges/distance) (  e  )  can also
be used to determine the size of a range  e  . Unlike  ranges  ::  size  (  e
)  ,  [ ranges::  distance
](http://en.cppreference.com/w/cpp/iterator/ranges/distance) (  e  )  works
even if  e  is an unsized range, at the cost of having linear complexity in
that case.

###  [ [ edit ](/mwiki/index.php?title=cpp/ranges/size&action=edit&section=2
"Edit section: Example") ]  Example

Run this code

    
    
    #include <iostream>
    #include <ranges>
    #include <type_traits>
    #include <vector>
     
    int main()
    {
        auto v = [std::vector](http://en.cppreference.com/w/cpp/container/vector)<int>{};
        [std::cout](http://en.cppreference.com/w/cpp/io/cout) << "ranges::size(v) == " << std::ranges::size(v) << '\n';
     
        auto il = {7};     // std::initializer_list
        [std::cout](http://en.cppreference.com/w/cpp/io/cout) << "ranges::size(il) == " << std::ranges::size(il) << '\n';
     
        int array[]{4, 5}; // array has a known bound
        [std::cout](http://en.cppreference.com/w/cpp/io/cout) << "ranges::size(array) == " << std::ranges::size(array) << '\n';
     
        static_assert([std::is_signed_v](http://en.cppreference.com/w/cpp/types/is_signed)<decltype(std::ranges::size(v))> == false);
    }

Output:

    
    
    ranges::size(v) == 0
    ranges::size(il) == 1
    ranges::size(array) == 2

###  [ [ edit ](/mwiki/index.php?title=cpp/ranges/size&action=edit&section=3
"Edit section: Defect reports") ]  Defect reports

The following behavior-changing defect reports were applied retroactively to
previously published C++ standards.

DR  |  Applied to  |  Behavior as published  |  Correct behavior   
---|---|---|---  
[ P2602R2 ](https://wg21.link/P2602R2) |  C++20  |  there's machinery to prohibit certain non-member ` size ` found by [ ADL ](/w/cpp/language/adl "cpp/language/adl") |  removed such machinery   
  
###  [ [ edit ](/mwiki/index.php?title=cpp/ranges/size&action=edit&section=4
"Edit section: See also") ]  See also

[ ranges::ssize  ](/w/cpp/ranges/ssize "cpp/ranges/ssize") (C++20)  |  returns a signed integer equal to the size of a range   
(customization point object)  [ [edit]
](https://en.cppreference.com/mwiki/index.php?title=Template:cpp/ranges/dsc_ssize&action=edit)  
---|---  
[ ranges::sized_range  ](/w/cpp/ranges/sized_range "cpp/ranges/sized range") (C++20)  |  specifies that a range knows its size in constant time   
(concept)  [ [edit]
](https://en.cppreference.com/mwiki/index.php?title=Template:cpp/ranges/dsc_sized_range&action=edit)  
[ ranges::distance  ](/w/cpp/iterator/ranges/distance "cpp/iterator/ranges/distance") (C++20)  |  returns the distance between an iterator and a sentinel, or between the beginning and end of a range   
(niebloid)  [ [edit]
](https://en.cppreference.com/mwiki/index.php?title=Template:cpp/iterator/ranges/dsc_distance&action=edit)  
[ size  ssize  ](/w/cpp/iterator/size "cpp/iterator/size") (C++17)  (C++20)  |  returns the size of a container or array   
(function template)  [ [edit]
](https://en.cppreference.com/mwiki/index.php?title=Template:cpp/iterator/dsc_size&action=edi