[英]How to intialize std::map of vectors of vectors?
我正在处理非常复杂的程序,我需要初始化 std::map 类型的变量std::map<int, std::vector<std::vector<std::array<std::byte, 2>>>>
作为 const 变量稍后进行一些比较。 我试着这样做:
const std::vector<std::vector<std::array<std::byte, 2>>>
boundaries_length_one = {{{std::byte('\x00'), std::byte('\x7f')}}};
const std::vector<std::vector<std::array<std::byte, 2>>>
boundaries_length_two = {{{std::byte('\xc2'), std::byte('\xdf')}, {std::byte('\x80'), std::byte('\xbf')}}};
const std::vector<std::vector<std::array<std::byte, 2>>> boundaries_length_three = {
{{std::byte('\xe0'), nullptr}, {std::byte('\xa0'), std::byte('\xbf')}, {std::byte('\x80'), std::byte('\xbf')}},
{{std::byte('\xe1'), std::byte('\xec')}, {std::byte('\x80'), std::byte('\xbf')},
{std::byte('\x80'), std::byte('\xbf')}},
{{std::byte('\xe0'), nullptr}, {std::byte('\x80'), std::byte('\x9f')}, {std::byte('\x80'), std::byte('\xbf')}},
{{std::byte('\xee'), std::byte('\xef')}, {std::byte('\x80'), std::byte('\xbf')},
{std::byte('\x80'), std::byte('\xbf')}}
};
const std::vector<std::vector<std::array<std::byte, 2>>> boundaries_length_four = {
{{std::byte('\xf0'), nullptr}, {std::byte('\x90'), std::byte('\xbf')}, {std::byte('\x80'), std::byte('\xbf')},
{std::byte('\x80'), std::byte('\xbf')}},
{{std::byte('\xf1'), std::byte('\xf3')}, {std::byte('\x80'), std::byte('\xbf')},
{std::byte('\x80'), std::byte('\xbf')}, {std::byte('\x80'), std::byte('\xbf')}},
{{std::byte('\xf4'), nullptr}, {std::byte('\x80'), std::byte('\x8f')}, {std::byte('\x80'), std::byte('\xbf')},
{std::byte('\x80'), std::byte('\xbf')}}
};
std::map<int, const std::vector<std::vector<std::array<std::byte, 2>>>> boundaries = {
{1, boundaries_length_one},
{2, boundaries_length_two},
{3, boundaries_length_three},
{4, boundaries_length_four}};
上面的代码位于单独的命名空间中。
不幸的是,我收到了这个错误:
In file included from /Users/denisivanenko/CLionProjects/UnicodeProcessorCpp/utf8.cpp:5:
/Users/denisivanenko/CLionProjects/UnicodeProcessorCpp/utf8.h:63:58: error: no matching constructor for initialization of 'const std::vector<std::vector<std::array<std::byte, 2> > >'
const std::vector<std::vector<std::array<std::byte, 2>>> boundaries_length_three = {
^ ~
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/vector:528:9: note: candidate template ignored: couldn't infer template argument '_InputIterator'
vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
^
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/vector:542:9: note: candidate template ignored: couldn't infer template argument '_ForwardIterator'
vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
^
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/vector:520:9: note: candidate constructor template not viable: requires 2 arguments, but 4 were provided
vector(_InputIterator __first,
^
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/vector:535:9: note: candidate constructor template not viable: requires 2 arguments, but 4 were provided
vector(_ForwardIterator __first,
^
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/vector:518:5: note: candidate constructor not viable: requires 3 arguments, but 4 were provided
vector(size_type __n, const value_type& __x, const allocator_type& __a);
^
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/vector:515:14: note: candidate constructor not viable: requires 2 arguments, but 4 were provided
explicit vector(size_type __n, const allocator_type& __a);
^
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/vector:517:5: note: candidate constructor not viable: requires 2 arguments, but 4 were provided
vector(size_type __n, const value_type& __x);
^
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/vector:558:5: note: candidate constructor not viable: requires 2 arguments, but 4 were provided
vector(const vector& __x, const allocator_type& __a);
^
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/vector:567:5: note: candidate constructor not viable: requires 2 arguments, but 4 were provided
vector(initializer_list<value_type> __il, const allocator_type& __a);
^
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/vector:578:5: note: candidate constructor not viable: requires 2 arguments, but 4 were provided
vector(vector&& __x, const allocator_type& __a);
^
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/vector:501:40: note: candidate constructor not viable: requires single argument '__a', but 4 arguments were provided
_LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a)
^
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/vector:513:14: note: candidate constructor not viable: requires single argument '__n', but 4 arguments were provided
explicit vector(size_type __n);
^
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/vector:557:5: note: candidate constructor not viable: requires single argument '__x', but 4 arguments were provided
vector(const vector& __x);
^
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/vector:564:5: note: candidate constructor not viable: requires single argument '__il', but 4 arguments were provided
vector(initializer_list<value_type> __il);
^
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/vector:570:5: note: candidate constructor not viable: requires single argument '__x', but 4 arguments were provided
vector(vector&& __x)
^
错误有点长,但各处的注释消息几乎相同,只是需要和提供的元素数量不同。
谁能帮我初始化这么复杂的结构? 我使用 C++17、clang 11.0.3 和 CMake 3.17.2。
我设法修复它。 问题出现在我用来代替 std::byte 的nullptr
中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.