std :: map和std :: variant的不完整类型

时间:2018-05-29 16:43:51

标签: c++ c++17 libstdc++ incomplete-type

考虑let found_variable_array = []; $('#message').on('keyup',function(){ suggest_array_sample = [ {array_val:"#{person1}"}, {array_val:"#{person2}"}, {array_val:"#{person3}"} ] let index = $.inArray($(this).val(), suggest_array_sample.map(o => o.array_val)); if (index >= 0) found_variable_array.push(suggest_array_sample[index]); console.log(found_variable_array); });之上的递归变体的这种简化且非常具体的实现:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<textarea id="message"></textarea>

由于尝试实例化std::variant而无法在gcc 7/8上编译,因为#include <map> #include <variant> struct recursive_tag; template <typename...> struct RecursiveVariant; template <> struct RecursiveVariant<int, std::map<int, recursive_tag>> : std::variant<int, std::map<int, RecursiveVariant<int, std::map<int, recursive_tag>>>> { using underlying = std::variant<int, std::map<int, RecursiveVariant<int, std::map<int, recursive_tag>>>>; using underlying::underlying; }; int main() { RecursiveVariant<int, std::map<int, recursive_tag>> rv; } 是一个不完整的类型,它本身会失败。

但是,编译器错误call-stack中没有任何内容向我指示为什么 std::pair<const int, recursive_tag>需要实例化。最重要的是:

  

变体:252:48:需要来自“recursive_tag

指着:

std::pair<const int, recursive_tag>

虽然在那里拼写了void std::__detail::__variant::__erased_dtor(_Variant&&) [with _Variant = const std::__detail::__variant::_Variant_storage<false, int, std::map<int, RecursiveVariant<int, std::map<int, recursive_tag, std::less<int>, std::allocator<std::pair<const int, recursive_tag> > > >, std::less<int>, std::allocator<std::pair<const int, RecursiveVariant<int, std::map<int, recursive_tag, std::less<int>, std::allocator<std::pair<const int, recursive_tag> > > > > > > >&; long unsigned int _Np = 0]类型,但应该实例化的实际249 template<typename _Variant, size_t _Np> 250 void 251 __erased_dtor(_Variant&& __v) 252 { std::_Destroy(std::__addressof(__get<_Np>(__v))); } 类型是map<int, recursive_tag> ...这应该只需要map的实例化。

只需完成map<int, RecursiveVariant<int, map<int, recursive_tag>>>(即添加pair<const int, RecursiveVariant<...>>)即可解决问题。但是什么导致问题开始?

1 个答案:

答案 0 :(得分:14)

line at issue来电

(sql/query db-spec (into [(str "SELECT ... WHERE col IN ("
                               (str/join "," (repeat (count values) "?"))
                               ")")]
                         values))

std::_Destroy(std::__addressof(__get<_Np>(__v))); 执行ADL的需要足以触发__get类型的任何和所有相关类的实例化,即__v,以寻找潜在的朋友函数(和函数模板)在这些类中定义了该名称。这包括让你绊倒的_Variant