为什么在std :: deque.erase上引发异常?

问题描述

尝试通过迭代器从/** * Child theme functions * * When using a child theme (see http://codex.wordpress.org/Theme_Development * and http://codex.wordpress.org/Child_Themes),you can override certain * functions (those wrapped in a function_exists() call) by defining them first * in your child theme's functions.PHP file. The child theme's functions.PHP * file is included before the parent theme's file,so the child theme * functions would be used. * * Text Domain: oceanwp * @link http://codex.wordpress.org/Plugin_API * */ /** * Load the parent style.css file * * @link http://codex.wordpress.org/Child_Themes */ function oceanwp_child_enqueue_parent_style() { // Dynamically get version number of the parent stylesheet (lets browsers re-cache your stylesheet when you update your theme) $theme = wp_get_theme( 'OceanWP' ); $version = $theme->get( 'Version' ); // Load the stylesheet wp_enqueue_style( 'child-style',get_stylesheet_directory_uri() . '/style.css',array( 'oceanwp-style' ),$version ); } add_action( 'wp_enqueue_scripts','oceanwp_child_enqueue_parent_style' ); 删除元素时抛出此错误错误是使用VS2017“无法寻求值初始化的迭代器”。我不知道为什么会这样,deque是不是一个双链表,它不会使std::deque / push_front()上的迭代器无效吗?

push_back()

解决方法

不是std :: deque双链表

不,不是。如documentation

中所述

std :: deque(双端队列)是一个索引序列容器,允许在其开始和结束时都进行快速插入和删除。此外,在双端队列的两端插入和删除绝对不会使其余元素的指针或引用无效。

重点是我的。请注意,它说的是指针或引用不是无效的,不是迭代器。 std::deque::push_front()上的文档明确指出:

所有迭代器(包括过去的迭代器)均无效。没有引用无效。

对于您要实现的逻辑,我建议使用boost::multi_index,因为它允许具有不同访问条件的单个容器,并且您不必保持2个容器同步。可以找到文档here