From 459ff9a9b4364b6f3893cde1a99a07e8719b41f4 Mon Sep 17 00:00:00 2001 From: Clement Jamin Date: Wed, 3 May 2017 16:47:06 +0200 Subject: [PATCH] Introduce CGAL_GENERATE_MEMBER_DETECTOR macro --- STL_Extension/include/CGAL/Has_member.h | 43 +++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 STL_Extension/include/CGAL/Has_member.h diff --git a/STL_Extension/include/CGAL/Has_member.h b/STL_Extension/include/CGAL/Has_member.h new file mode 100644 index 00000000000..f4d243fa8ad --- /dev/null +++ b/STL_Extension/include/CGAL/Has_member.h @@ -0,0 +1,43 @@ +// Copyright (c) 2017 Inria (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. +// +// +// +// Author(s) : Clement Jamin + +#ifndef CGAL_HAS_MEMBER_H +#define CGAL_HAS_MEMBER_H + +// Macro used to check if a type T has a member named `X` +// It generates a class has_X where has_X::value is a boolean +// See example in Concurrent_compact_container.h +#define CGAL_GENERATE_MEMBER_DETECTOR(X) \ +template class has_##X { \ + struct Fallback { int X; }; \ + struct Derived : T, Fallback { }; \ + \ + template struct Check; \ + \ + typedef char ArrayOfOne[1]; \ + typedef char ArrayOfTwo[2]; \ + \ + template static ArrayOfOne & func( \ + Check *); \ + template static ArrayOfTwo & func(...); \ + public: \ + typedef has_##X type; \ + enum { value = sizeof(func(0)) == 2 }; \ +} // semicolon is after the macro call + +#endif // CGAL_HAS_MEMBER_H