我正在开发非常复杂的程序,我需要将std::map<int, std::vector<std::vector<std::array<std::byte, 2>>>>
类型的std :: map变量初始化为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
中。