How to restrict template parameter to pointer or random access iterator only?

后端 未结 1 1454
轻奢々
轻奢々 2021-01-19 07:19

Is there a way to restrict the parameter type of a template function to only pointers or random-access iterators?

Say I am developing a sorting function which works

1条回答
  •  被撕碎了的回忆
    2021-01-19 07:57

    Use iterator traits:

    static_assert(
        std::is_same::iterator_category>::value,
        "The mySort() function only accepts random access iterators or raw pointers to an array.\n");
    

    0 讨论(0)
提交回复
热议问题