I recently started to learn the new features introduced in C++20. I have some trouble to implement concepts.
Toy examples: I would like to define a concept representing a resizable array:
template<class T>
concept ResizableArray= std::is_same<std::vector<double>, T>::value;
Such code compiles under Visual Studio and works well. However, I am stuck writing a concept representing a fixed-size array of any size (std::array<double, 1>, std::array<double, 2> ... should be valid). My attempt:
template<template<unsigned int> class T, unsigned int S>
concept FixedArray = std::is_same<std::array<double, S>, T<double, S>>::value;
does not compile!
Questions:
- Where is the mistake?
- How can I write a concept that represents a fixed-size array or a resizable array? My attempt
template<template<unsigned int> class T, unsigned int S>
concept Array= std::is_same<std::vector<double>, T>::value || std::is_same<std::array<double, S>, T<S>>::value;
does not compile!
Any suggestions would be appreciated.