std::forward_list::insert_after implementation

1 week ago 9
ARTICLE AD BOX
struct base_node { base_node* _next = nullptr; }; template <typename T> struct node: base_node { T _value; node() = default; explicit node(const T& v) : _value(v) {} explicit node(T&& v) : _value(std::move(v)) {} }; template <bool isConst> class base_iterator { using base_node_t = std::conditional_t<isConst, const __fl_detail::base_node, __fl_detail::base_node>; using node_t = std::conditional_t<isConst, const __fl_detail::node<T>, __fl_detail::node<T>>; using iterator = base_iterator<false>; using const_iterator = base_iterator<true>; iterator insert_after(const_iterator pos, const_reference value) { // ????? we need used const_cast?? }

How can I add an element via a const_iterator? Should I use const_cast? Is it possible to do without it, and how can I implement this method more correctly?

Read Entire Article