CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Thread: Array of constant values as template parameter

Threaded View

  1. #1
    Join Date
    Jun 2002
    Location
    Germany
    Posts
    1,557

    Array of constant values as template parameter

    Hello,

    It's been a while since I checked in here.

    Is it possible to use an array of constant values as a template parameter. I am writing preliminary benchmark code for ISO/IEC 14882:2011, so I could also use std::array or std::initializer_list.

    In the mathematical template below, I use integer coefficients. The template has order 3.

    Code:
    template<const std::size_t order,
             const std::uint_least16_t B0,
             const std::uint_least16_t B1,
             const std::uint_least16_t B2,
             const std::uint_least16_t B3>
    struct order3_math
    {
      // Do order-3 math.
    };
    If I want to write more generic code, I could use order N and an array-type template parameter. But it does not work with compilers like VS2010 and GCC 4.6.x. Can it work or *should* something like this ever work without variadic templates?

    Code:
    // Can I do anything like this?
    template<const std::size_t order,
             const std::array<std::uint_least16_t, order> coefficients>
    struct orderN_math
    {
      // Do order-N math.
    };
    Thank you.
    Sincerely, Chris.
    Last edited by dude_1967; September 19th, 2011 at 07:40 AM. Reason: Simplified the code example.
    You're gonna go blind staring into that box all day.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)