#include <iostream>#include <concepts>#include <iterator>#include <vector>#include <forward_list>#include <list>template<std::random_access_iteratorI>voidf(constchar*name){std::cout<<name<<" is random_access_iterator"<<std::endl;}template<typenameI>voidf(constchar*name){std::cout<<name<<" is not random_access_iterator"<<std::endl;}structsample_random_access_iterator{friendautooperator++(sample_random_access_iterator&)->sample_random_access_iterator&;friendautooperator++(sample_random_access_iterator&,int)->sample_random_access_iterator;friendautooperator--(sample_random_access_iterator&)->sample_random_access_iterator&;friendautooperator--(sample_random_access_iterator&,int)->sample_random_access_iterator;friendautooperator+(constsample_random_access_iterator&,int)->sample_random_access_iterator;friendautooperator+(int,constsample_random_access_iterator&)->sample_random_access_iterator;friendautooperator+=(sample_random_access_iterator&,int)->sample_random_access_iterator&;friendautooperator-(constsample_random_access_iterator&,int)->sample_random_access_iterator;friendautooperator-=(sample_random_access_iterator&,int)->sample_random_access_iterator&;friendautooperator-(constsample_random_access_iterator&,constsample_random_access_iterator&)->int;friendautooperator*(constsample_random_access_iterator&)->int&;autooperator[](int)const->int&;friendstd::strong_orderingoperator<=>(constsample_random_access_iterator&,constsample_random_access_iterator&);friendbooloperator==(constsample_random_access_iterator&,constsample_random_access_iterator&);usingdifference_type=int;usingvalue_type=int;usingiterator_category=std::random_access_iterator_tag;};intmain(){f<int*>("int*");f<constint*>("const int*");f<std::vector<int>::iterator>("std::vector<int>::iterator");f<sample_random_access_iterator>("sample_random_access_iterator");std::cout<<"\n";f<int*const>("int* const");f<std::forward_list<int>::iterator>("std::forward_list<int>::iterator");f<std::list<int>::iterator>("std::list<int>::iterator");f<std::istream_iterator<double>>("std::istream_iterator<double>");f<std::ostream_iterator<double>>("std::ostream_iterator<double>");}
出力
int* is random_access_iterator
const int* is random_access_iterator
std::vector<int>::iterator is random_access_iterator
sample_random_access_iterator is random_access_iterator
int* const is not random_access_iterator
std::forward_list<int>::iterator is not random_access_iterator
std::list<int>::iterator is not random_access_iterator
std::istream_iterator<double> is not random_access_iterator
std::ostream_iterator<double> is not random_access_iterator
You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.