diff --git a/BGL/doc/BGL/PackageDescription.txt b/BGL/doc/BGL/PackageDescription.txt index b161c7d056e..61c319cac63 100644 --- a/BGL/doc/BGL/PackageDescription.txt +++ b/BGL/doc/BGL/PackageDescription.txt @@ -157,6 +157,7 @@ user might encounter. - `CGAL::clear()` - `CGAL::copy_face_graph()` +- `CGAL::reserve()` ## Iterators ## - `CGAL::Halfedge_around_source_iterator` diff --git a/BGL/include/CGAL/boost/graph/helpers.h b/BGL/include/CGAL/boost/graph/helpers.h index 9e1f54c36b6..dbfb00d3ad9 100644 --- a/BGL/include/CGAL/boost/graph/helpers.h +++ b/BGL/include/CGAL/boost/graph/helpers.h @@ -25,6 +25,7 @@ #include #include #include +#include namespace CGAL { @@ -725,6 +726,21 @@ clear_impl(FaceGraph& g) } } + +template +inline +typename boost::enable_if, void>::type +reserve_impl(FaceGraph& g, T nv, T ne, T nf) +{ + g.reserve(); +} + +template +inline +typename boost::disable_if, void>::type +reserve_impl(FaceGraph& g, T, T, T) +{} + } /** @@ -752,6 +768,26 @@ void clear(FaceGraph& g) } +/** + * \ingroup PkgBGLHelperFct + * + * If the graph has a member function `reserve()`, it will be called. + * + * @tparam FaceGraph model of `MutableHalfedgeGraph` and `MutableFaceGraph` + * + * @param g the graph + * @param nv number of vertices + * @param ne number of edges + * @param nf number of faces + * + **/ +template +void reserve(FaceGraph& g, T nv, T ne, T nf) +{ + internal::reserve_impl(g,nv, ne, nf); +} + + } // namespace CGAL // Include "Euler_operations.h" at the end, because its implementation diff --git a/BGL/include/CGAL/boost/graph/internal/Has_member_reserve.h b/BGL/include/CGAL/boost/graph/internal/Has_member_reserve.h new file mode 100644 index 00000000000..bd2adbcfa7a --- /dev/null +++ b/BGL/include/CGAL/boost/graph/internal/Has_member_reserve.h @@ -0,0 +1,45 @@ +// Copyright (c) 2016 GeometryFactory (France). All rights reserved. +// +// This file is part of CGAL (www.cgal.org); you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 3 of the License, +// or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// +// Author(s) : Sebastien Loriot + + +#ifndef CGAL_HAS_MEMBER_RESERVE_H +#define CGAL_HAS_MEMBER_RESERVE_H + +namespace CGAL { +namespace internal { + +template +class Has_member_reserve +{ +private: + template + class check {}; + + template + static char f(check*); + + template + static int f(...); +public: + static const bool value = (sizeof(f(0)) == sizeof(char)); +}; + +} // internal +} // CGAL + +#endif /* CGAL_HAS_MEMBER_RESERVE_H */