d_range ` for cv-
unqualified program-defined types. Such specializations shall be usable in [
constant expressions ](/w/cpp/language/constant_expression
"cpp/language/constant expression") and have type  const  bool  .

##  Contents

  * 1  Semantic requirements 
  * 2  Notes 
  * 3  Example 
  * 4  See also 

  
---  
  
###  [ [ edit
](/mwiki/index.php?title=cpp/ranges/sized_range&action=edit&section=1 "Edit
section: Semantic requirements") ]  Semantic requirements

1)  Given an lvalue ` t ` of type  [ std::  remove_reference_t
](http://en.cppreference.com/w/cpp/types/remove_reference) < T  > , ` T `
models ` sized_range ` only if

  * [ ranges::  size  ](http://en.cppreference.com/w/cpp/ranges/size) (  t  ) 

    

  * has amortized constant-time complexity, 
  * does not alter the value of ` t ` in a manner observable to [ equality-preserving ](/w/cpp/concepts#Equality_preservation "cpp/concepts") expressions, and 
  * is equal to  [ ranges::  distance  ](http://en.cppreference.com/w/cpp/iterator/ranges/distance) (  [ ranges::  begin  ](http://en.cppreference.com/w/cpp/ranges-ranges-placeholder/begin) (  t  )  , [ ranges::  end  ](http://en.cppreference.com/w/cpp/ranges-ranges-placeholder/end) (  t  )  )  , and 

  * if  [ ranges::  iterator_t  ](http://en.cppreference.com/w/cpp/ranges-ranges-placeholder/iterator_t) < T  > models [ ` forward_iterator ` ](/w/cpp/iterator/forward_iterator "cpp/iterator/forward iterator") ,  [ ranges::  size  ](http://en.cppreference.com/w/cpp/ranges/size) (  t  )  is well-defined regardless of the evaluation of  [ ranges::  begin  ](http://en.cppreference.com/w/cpp/ranges-ranges-placeholder/begin) (  t  )  (in other words, a single-pass sized range may support a call to size only before the first call to begin, but a forward range must support size at all times). 

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

` disable_sized_range ` cannot be used to opt-out a range whose iterator and
sentinel satisfy [ ` sized_sentinel_for ` ](/w/cpp/iterator/sized_sentinel_for
"cpp/iterator/sized sentinel for") ;  [ std::disable_sized_sentinel_for
](/w/cpp/iterator/sized_sentinel_for "cpp/iterator/sized sentinel for") must
be used instead.

` disable_sized_range ` cannot be specialized for array types or reference
types.

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

Run this code

    
    
    #include <forward_list>
    #include <list>
    #include <ranges>
     
    static_assert
    (
        std::ranges::sized_range<[std::list](http://en.cppreference.com/w/cpp/container/list)<int>> and
        not std::ranges::sized_range<[std::forward_list](http://en.cppreference.com/w/cpp/container/forward_list)<int>>
    );
     
    int main() {}

###  [ [ edit
](/mwiki/index.php?title=cpp/ranges/sized_range&action=edit&section=4 "Edit
section: See also") ]  See also

[ ranges::random_access_range  ](/w/cpp/ranges/random_access_range "cpp/ranges/random access range") (C++20)  |  specifies a range whose iterator type satisfies [ ` random_access_iterator ` ](/w/cpp/iterator/random_access_iterator "cpp/iterator/random access iterator")   
(concept)  [ [edit]
](https://en.cppreference.com/mwiki/index.php?title=Template:cpp/ranges/dsc_random_access_range&action=edit)  
---|---  
[ ranges::contiguous_range  ](/w/cpp/ranges/contiguous_range "cpp/ranges/contiguous range") (C++20)  |  specifies a range whose iterator type satisfies [ ` contiguous_iterator ` ](/w/cpp/iterator/contiguous_iterator "cpp/iterator/contiguous iterator")   
(concept)  [ [edit]
](https://en.cppreference.com/mwiki/index.php?title=Template:cpp/ranges/dsc_contiguous_range&action=edit)  
  
Retrieved from " [
https://en.cppreference.com/mwiki/index.php?title=cpp/ranges/sized_range&oldid=160933
](https://en.cppreference.com/mwiki/index.php?title=cpp/ranges/sized_range&oldid=160933)
"

#####  Navigation

  *