I need to write a function for parsing JSON object. For convinience I decided to use templates for doing that.
So, my function looks as follows:
template<typename ValueType>
ValueType get(const Json& json);
For each type of values i want to receive from JSON there is a specialization:
template<>
uint8_t get(const Json& json);
template<>
double get(const Json& json);
template<>
std::string get(const Json& json);
...
Now I want to extend this function and add the ability to receive containers of elements. As I understand for achieving that I need to add specialization for every container type and every value type:
template<>
std::vector<uint8_t> get(const Json& json);
template<>
std::vector<std::string> get(const Json& json);
...
It is absolutely not convinient because of N*N complexity. Instead of doing that I want have something like this:
template<typename ValueType>
std::vector<ValueType> get<std::vector<ValueType>>(const Json& json);
or even this:
template<template<typename...> class Container, typename ValueType>
Container<ValueType> get(const Json& json);
But if I try to write such templates, i receive the error:
error: function template partial specialization ‘getstd::vector<_RealType >’ is not allowed std::vector getstd::vector<ValueType>(const Json& json);
How should I refactor the function for achieving my goal?