/******************************************************************************
Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, PHP, Ruby,
C#, VB, Perl, Swift, Prolog, Javascript, Pascal, HTML, CSS, JS
Code, Compile, Run and Debug online from anywhere in world.
*******************************************************************************/
#include <iostream>
struct GPIOB
{
void static Set()
{
std::cout << "GPIOB" ;
}
} ;
struct GPIOA
{
void static Set()
{
std::cout << "GPIOA" ;
}
} ;
template <typename T, std::size_t pinNum>
struct Port
{
constexpr static std::size_t btn = pinNum ;
static void Set()
{
T::Set() ;
std::cout << "." << btn << ".Set" << std::endl;
}
} ;
template<typename ...T>
struct PinsPack
{
} ;
template<typename ... Types> struct Collection
{
};
template<std::size_t index, typename Type>
struct CollectionList
{
} ;
template<std::size_t index, typename T, typename ...Ts>
struct CollectionList<index, Collection<T, Ts...>>
{
using type = typename CollectionList<index - 1, Collection<Ts...>>::type ;
} ;
template<typename T, typename ...Ts>
struct CollectionList<0, Collection<T, Ts...>>
{
using type = T;
} ;
//=============================
template<std::size_t size, typename TPort, typename... Acc>
struct Create
{
using Pin = Port<TPort, size> ;
using type = typename Create<size - 1, TPort, Pin, Acc...>::type ;
using Result = Collection<Acc...> ;
} ;
template<typename TPort, typename... Acc>
struct Create<0, TPort, Acc...>
{
using Pin = Port<TPort, 0> ;
using type = Collection<Pin, Acc...> ;
using Result = Collection<Acc...> ;
} ;
template<std::size_t size, typename T>
using GeneratePins = typename Create<size, T>::type ;
// Сгенерируем список пинов для портов с типом
// PinsPack<Port<GPIOB, 0>, Port<GPIOB, 1> ... Port<GPIOB, 15>>
//using GpiobPort = ;
// Тоже самое для порта А
using GpioaPort = GeneratePins<15, GPIOA> ;
template<size_t index>
using Gpioa = typename CollectionList<index, GpioaPort>::type ;
template<size_t index>
using Gpiob = typename CollectionList<index, GeneratePins<15, GPIOB>>::type ;
int main()
{
Gpioa<0>::Set() ;
Gpiob<1>::Set() ;
Gpioa<2>::Set() ;
Gpiob<11>::Set() ;
return 0;
}