Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std::pair<std::string,Color> 序列化枚举不支持 #227

Open
424358225 opened this issue Sep 20, 2023 · 9 comments
Open

std::pair<std::string,Color> 序列化枚举不支持 #227

424358225 opened this issue Sep 20, 2023 · 9 comments

Comments

@424358225
Copy link

这是普通代码支持的

std::pair<std::string,Color> a;
auto asff = std::make_pair("J1",Color::RED);

如果将这个结构序列化,则会编译失败

enum class Color {
BULE = 10,
RED = 15,
};
namespace iguana {
template <> struct enum_value<Color> {
  constexpr static std::array<int, 2> value = {10, 15};
};
}
struct test_enum_t {
std::pair<std::string,Color> a;
};
REFLECTION(test_enum_t, a);

@424358225
Copy link
Author

报错如下

/home/td/Test/iguana/yaml_writer.hpp:161: error: no matching function for call to ‘render_yaml_value(std::__cxx11::basic_string<char>&, std::pair<std::__cxx11::basic_string<char>, Color>&, long unsigned int)’
  161 |                render_yaml_value(s, t.*v, min_spaces + 1);
      |                ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
      /home/td/Test/iguana/yaml_writer.hpp:13: error: no type named ‘type’ in ‘struct std::enable_if<false, int>’
   13 |           std::enable_if_t<refletable_v<T>, int> = 0>
      |                                                    ^

@bbbgan
Copy link
Collaborator

bbbgan commented Sep 20, 2023

你是打算设置键值是pair类型的吗?pair类型的键值是无法表示的吧,
#180 这个和您的问题是一样的吗?

@424358225
Copy link
Author

你是打算设置键值是pair类型的吗?pair类型的键值是无法表示的吧, #180 这个和您的问题是一样的吗?

并不是,单纯的一个组队关系 不是map

@bbbgan
Copy link
Collaborator

bbbgan commented Sep 22, 2023

你是打算设置键值是pair类型的吗?pair类型的键值是无法表示的吧, #180 这个和您的问题是一样的吗?

并不是,单纯的一个组队关系 不是map

能给出报错的完整测试代码吗

@424358225
Copy link
Author

/home/td/Test/iguana/yaml_writer.hpp:13: error: no type named ‘type’ in ‘struct std::enable_if<false, int>’
13 | std::enable_if_t<refletable_v, int> = 0>
|

@bbbgan
Copy link
Collaborator

bbbgan commented Sep 25, 2023

抱歉,我还是没有理解你的意思,我目前的理解是你想序列化结构体中的 pair类型 ? 这是目前不允许的,因为key和value是一对一的情况,pair类型属于一对多。目前没有考虑去序列化pair类型!

@424358225
Copy link
Author

抱歉,我还是没有理解你的意思,我目前的理解是你想序列化结构体中的 pair类型 ? 这是目前不允许的,因为key和value是一对一的情况,pair类型属于一对多。目前没有考虑去序列化pair类型!

好的,明白了.
enum States{
S_A = 0,
S_C ,
};

如果定义std::map<States,int> 这样的结构,也会出现编译错误. 报错跟上述一致.
这里不能隐式专为int吗?

@bbbgan
Copy link
Collaborator

bbbgan commented Sep 25, 2023

隐式转换是不提倡的,为什么需要定义 std::map<States,int> 这样的结构呢?

@424358225
Copy link
Author

隐式转换是不提倡的,为什么需要定义 std::map<States,int> 这样的结构呢?

哈哈,接手的屎山代码只能慢慢改

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants