C ++逆整数序列实现 [英] c++ reversed integer sequence implementation

查看:53
本文介绍了C ++逆整数序列实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁知道如何实现C ++ std :: make_index_sequence 反向版本。得到- make_index_sequence_reverse< int,5> =< 4,3,2,1,0> 。谢谢!

Who knows how to implement C++ std::make_index_sequence reverse version. To get - make_index_sequence_reverse<int, 5> = <4,3,2,1,0>. Thank you!

推荐答案

恕我直言,没有理由使用 index_sequence_reverse std :: index_sequence 支持索引序列,并且是顺序中性的(甚至没有顺序)。

IMHO, there is no reason for a index_sequence_reverse: std::index_sequence support sequences of indexes and are order neutral (or even without order).

如果可以使用 std :: make_index_sequence ,对于 makeIndexSequenceReverse 您可以进行以下操作

If you can use std::make_index_sequence, for a makeIndexSequenceReverse you can make something as follows

#include <utility>
#include <type_traits>

template <std::size_t ... Is>
constexpr auto indexSequenceReverse (std::index_sequence<Is...> const &)
   -> decltype( std::index_sequence<sizeof...(Is)-1U-Is...>{} );

template <std::size_t N>
using makeIndexSequenceReverse
   = decltype(indexSequenceReverse(std::make_index_sequence<N>{}));

int main ()
 {
   static_assert( std::is_same<std::index_sequence<4U, 3U, 2U, 1U, 0U>,
      makeIndexSequenceReverse<5U>>::value, "!" );
 }

这篇关于C ++逆整数序列实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆