-
Hi 👋 I've implemented my own trait like that: template<class T>
struct CustomTraits : public tao::json::traits<T> {
TAO_JSON_DEFAULT_KEY("custom");
};
template<> struct CustomTraits<SDL_FPoint> {
TAO_JSON_DEFAULT_KEY("point");
template<template<class...> class Traits>
static void assign(tao::json::basic_value<Traits> &value, const SDL_FPoint &point);
template<template<class...> class Traits>
static SDL_FPoint as(const tao::json::basic_value<Traits> &value);
template<template<class...> class Traits>
static void to(const tao::json::basic_value<Traits> &value, SDL_FPoint &point);
template<template<class...> class Traits>
static bool equal(const tao::json::basic_value<Traits> &value, const SDL_FPoint &point) noexcept;
template<template<class...> class Traits>
static bool less_than(const tao::json::basic_value<Traits> &value, const SDL_FPoint &point) noexcept;
template<template<class...> class Traits>
static bool greater_than(const tao::json::basic_value<Traits> &value, const SDL_FPoint &point) noexcept;
template<template<class...> class Traits, class Consumer>
static void produce(Consumer &c, const SDL_FPoint &point);
};
template<class T>
using custom_trait = CustomTraits<T>;
using custom_value = tao::json::basic_value<CustomTraits>; PS: (I hided the implementations to make this question shorter) So, I'm trying to read the file and initialize my std::shared_ptr<custom_value> config{};
if (fs::ifstream file{ origin, std::ios::binary | std::ios::ate }; file) {
const auto size{ file.tellg() };
file.seekg(std::ios::beg);
std::string content(size, '\0');
file.read(&content[0], size);
config = std::make_shared<custom_value>(
tao::json::basic_from_string<custom_traits>(std::move(content))
);
} But I get a lot of template errors. They are about Before this error, I'd gotten the error inside Please, could you help me to initialize my custom |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Oh. And |
Beta Was this translation helpful? Give feedback.
-
First, this problem has nothing to do with The type alias And third, |
Beta Was this translation helpful? Give feedback.
First, this problem has nothing to do with
std::shared_ptr
. Second, it works for me when I usetao::json::basic_from_string<CustomTraits>
instead oftao::json::basic_from_string<custom_trait>
.The type alias
custom_trait
doesn't add anything, and I'm not really surprised that your example doesn't work given that templated type aliases aren't quite a replacement for class templates like normal type aliases are for classes/types, though I would have expected some different error.And third,
basic_from_file
andbasic_from_stream
also work when usingCustomTraits
instead ofcustom_trait
. Does this small change work for you, too?