diff --git a/ioc/iochooks.cpp b/ioc/iochooks.cpp index ae1a4e6..35dc5cd 100644 --- a/ioc/iochooks.cpp +++ b/ioc/iochooks.cpp @@ -69,32 +69,33 @@ void pvxsr(int detail) } } -template -struct index_sequence {}; +// index_sequence from: +//http://stackoverflow.com/questions/17424477/implementation-c14-make-integer-sequence -template -struct next_index_sequence {}; - -template -struct next_index_sequence> -{ - typedef index_sequence type; +template< std::size_t ... I > +struct index_sequence { + using type = index_sequence; + using value_type = std::size_t; + static constexpr std::size_t size() { + return sizeof ... (I); + } }; -template -struct build_index_sequence -{ - typedef typename build_index_sequence::type type; -}; +template< typename Seq1, typename Seq2 > +struct concat_sequence; -template -struct build_index_sequence -{ - typedef index_sequence type; -}; +template< std::size_t ... I1, std::size_t ... I2 > +struct concat_sequence< index_sequence< I1 ... >, index_sequence< I2 ... > > : public index_sequence< I1 ..., (sizeof ... (I1)+I2) ... > {}; -template -using make_index_sequence = typename build_index_sequence<0, sizeof...(Args)>::type; +template< std::size_t I > +struct make_index_sequence : public concat_sequence< typename make_index_sequence< I/2 >::type, + typename make_index_sequence< I-I/2 >::type > {}; + +template<> +struct make_index_sequence< 0 > : public index_sequence<> {}; + +template<> +struct make_index_sequence< 1 > : public index_sequence< 0 > {}; template struct Arg; @@ -140,8 +141,9 @@ struct Reg { template void doit(index_sequence) { - static const iocshArg args[sizeof...(Args)] = {{argnames[Idxs], Arg::code}...}; - static const iocshFuncDef def = {name, sizeof...(Args), (const iocshArg* const*)&args}; + static const iocshArg argstack[sizeof...(Args)] = {{argnames[Idxs], Arg::code}...}; + static const iocshArg * const args[] = {&argstack[Idxs]...}; + static const iocshFuncDef def = {name, sizeof...(Args), args}; iocshRegister(&def, &call); } @@ -149,7 +151,7 @@ struct Reg { template void ister() { - doit(make_index_sequence{}); + doit(make_index_sequence{}); } };