mardi 27 mars 2018

Using an instance of an std::array

I'm trying to create some sort of comparison function that will compare certain prefixes that are known at compile time to other buffers.

I'm trying to use the predefined std::arrays that hold the prefixes as template parameters.

Here is what I tried:

constexpr std::array<std::uint8_t, 4> ARRAY_A ;
constexpr std::array<std::uint8_t, 4> ARRAY_B ;

enum class Foo{
    A,B

    };

template<size_t SizeOfHeader, std::array<std::uint8_t, SizeOfHeader> Header, Foo f> 
void foo()
{
    std::cout << __PRETTY_FUNCTION__ << std::endl;
}

template<template<class, class> class TContainer, Foo f> 
void foo2()
{
    std::cout << __PRETTY_FUNCTION__ << std::endl;
}


int main()
{
    foo2<ARRAY_A, Foo::A>();
    foo<ARRAY_A.size(), ARRAY_A, Foo::A>();
    return 0;
} 

These attempts were made after reading the following answers which seemed related: 1 , 2.

I'm interested in understanding the errors in the code as much as finding a working solution :)

Here is the failed attempt at coliru. The errors are:

main.cpp:31:5: error: no matching function for call to 'foo2'
    foo2<ARRAY_A, Foo::A>();
    ^~~~~~~~~~~~~~~~~~~~~
main.cpp:23:6: note: candidate template ignored: invalid explicitly-specified argument for template parameter 'TContainer'
void foo2()
     ^
main.cpp:32:5: error: no matching function for call to 'foo'
    foo<ARRAY_A.size(), ARRAY_A, Foo::A>();
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:17:6: note: candidate template ignored: invalid explicitly-specified argument for template parameter 'Header'
void foo()
     ^
2 errors generated.

Aucun commentaire:

Enregistrer un commentaire