See More

// Copyright (C) 2017-2019 Jonathan Müller // This file is subject to the license terms in the LICENSE file // found in the top-level directory of this distribution. #ifndef CPPAST_CPP_ENTITY_CONTAINER_HPP_INCLUDED #define CPPAST_CPP_ENTITY_CONTAINER_HPP_INCLUDED #include namespace cppast { /// Helper class for entities that are containers. /// /// Inherit from it to generate container access. template class cpp_entity_container { public: using iterator = typename detail::intrusive_list::const_iterator; /// \returns A const iterator to the first child. iterator begin() const noexcept { return children_.begin(); } /// \returns A const iterator to the last child. iterator end() const noexcept { return children_.end(); } protected: /// \effects Adds a new child to the container. void add_child(std::unique_ptr ptr) noexcept { children_.push_back(static_cast(*this), std::move(ptr)); } /// \returns A non-const iterator to the first child. typename detail::intrusive_list::iterator mutable_begin() noexcept { return children_.begin(); } /// \returns A non-const iterator one past the last child. typename detail::intrusive_list::iterator mutable_end() noexcept { return children_.begin(); } ~cpp_entity_container() noexcept = default; private: detail::intrusive_list children_; }; } // namespace cppast #endif // CPPAST_CPP_ENTITY_CONTAINER_HPP_INCLUDED