mirror of https://github.com/CGAL/cgal
Remove CGAL::Overload
Equivalent and better functionality is provided by http://www.boost.org/libs//functional/overloaded_function/doc/html/index.html
This commit is contained in:
parent
ece2fa38d4
commit
728cfaa456
|
|
@ -35,7 +35,6 @@
|
||||||
\input{STL_Extension_ref/tuple.tex}
|
\input{STL_Extension_ref/tuple.tex}
|
||||||
\input{STL_Extension_ref/Complexity_tags.tex}
|
\input{STL_Extension_ref/Complexity_tags.tex}
|
||||||
\input{STL_Extension_ref/Default.tex}
|
\input{STL_Extension_ref/Default.tex}
|
||||||
\input{STL_Extension_ref/overload.tex}
|
|
||||||
|
|
||||||
%%\cgalColumnLayout
|
%%\cgalColumnLayout
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,45 +0,0 @@
|
||||||
\begin{ccRefClass}{Overload}
|
|
||||||
|
|
||||||
\ccInclude{CGAL/Overload.h}
|
|
||||||
|
|
||||||
\ccDefinition
|
|
||||||
|
|
||||||
A class to bundle multiple unary \ccStyle{std::function} or
|
|
||||||
\ccStyle{boost::function} objects into a single class that overloads
|
|
||||||
\ccStyle{operator()} for all arguments.
|
|
||||||
|
|
||||||
The return type of the overloaded \ccStyle{operator()} is the
|
|
||||||
\ccStyle{result_type} of the first argument that was used to create
|
|
||||||
the overload. The return types of the other function objects should be
|
|
||||||
convertible to this type.
|
|
||||||
|
|
||||||
This class requires a compiler with support for variadic templates,
|
|
||||||
rvalues, and tuple.
|
|
||||||
|
|
||||||
The requirements on the argument list \ccStyle{Args} are as follows:
|
|
||||||
Every element must be of type \ccStyle{std::function<T(U)>}, where T
|
|
||||||
is implicitly convertible to the nested \ccStyle{result_type} in the
|
|
||||||
first argument of the list.
|
|
||||||
|
|
||||||
\ccCreation
|
|
||||||
|
|
||||||
\ccConstructor{Overload<Args...>(Args...&&)}
|
|
||||||
{creates an Overload for the function objects Args...}
|
|
||||||
|
|
||||||
\ccFunction{template<typename Args...> Overload<Args...> make_overload(Args&&...);}
|
|
||||||
{Returns an Overload constructed from the arguments.}
|
|
||||||
|
|
||||||
\ccOperations
|
|
||||||
|
|
||||||
\ccMethod{template<typename T> result_type operator()(T& t);}
|
|
||||||
{Calls the function that matches the argument \ccStyle{t} best.}
|
|
||||||
|
|
||||||
\ccNestedType{result_type}{The return type of operator()}
|
|
||||||
|
|
||||||
\ccIncludeExampleCode{STL_Extension/Overload.cpp}
|
|
||||||
|
|
||||||
\ccSeeAlso
|
|
||||||
\ccAnchor{http://wiki.apache.org/stdcxx/C++0xCompilerSupport}{Apache C++11 Compiler support matrix}
|
|
||||||
|
|
||||||
|
|
||||||
\end{ccRefClass}
|
|
||||||
|
|
@ -1,19 +0,0 @@
|
||||||
#include <iostream>
|
|
||||||
#include <CGAL/Overload.h>
|
|
||||||
#include <CGAL/compiler_config.h>
|
|
||||||
|
|
||||||
// This file requires a compiler with support for the C++0x features auto and lambda
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
#if !defined(CGAL_CFG_NO_CPP0X_VARIADIC_TEMPLATES) && !defined(CGAL_CFG_NO_CPP0X_TUPLE) && !defined(CGAL_CFG_NO_CPP0X_RVALUE_REFERENCE)
|
|
||||||
auto overload = make_overload(
|
|
||||||
function<int(int)>([](int) { return 1; }),
|
|
||||||
function<int(char)>([](char) { return 2; }),
|
|
||||||
function<int(double)>([](double) { return 3; })
|
|
||||||
);
|
|
||||||
|
|
||||||
std::cout << o(1) << o('a') << " " << o(2.0) << std::endl;
|
|
||||||
#endif
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
@ -1,52 +0,0 @@
|
||||||
#ifndef CGAL_OVERLOAD_H
|
|
||||||
#define CGAL_OVERLOAD_H
|
|
||||||
|
|
||||||
#include <CGAL/compiler_config.h>
|
|
||||||
|
|
||||||
#if !defined(CGAL_CFG_NO_CPP0X_VARIADIC_TEMPLATES) && !defined(CGAL_CFG_NO_CPP0X_TUPLE) && !defined(CGAL_CFG_NO_CPP0X_RVALUE_REFERENCE)
|
|
||||||
|
|
||||||
#include <tuple>
|
|
||||||
|
|
||||||
namespace CGAL {
|
|
||||||
|
|
||||||
template<typename T, std::size_t i, class U >
|
|
||||||
struct Overload_helper : public Overload_helper<T, i - 1, U> {
|
|
||||||
typedef typename std::tuple_element<i - 1, T>::type inner_type;
|
|
||||||
|
|
||||||
typename inner_type::result_type operator()(typename inner_type::argument_type x) {
|
|
||||||
return std::get<i - 1>(static_cast<U*>(this)->t)(x); }
|
|
||||||
|
|
||||||
using Overload_helper<T, i - 1, U>::operator();
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename T, class U>
|
|
||||||
struct Overload_helper<T, 1, U> {
|
|
||||||
typedef typename std::tuple_element<0 ,T>::type inner_type;
|
|
||||||
|
|
||||||
typename inner_type::result_type operator()(typename inner_type::argument_type x) {
|
|
||||||
return std::get<0>(static_cast<U*>(this)->t)(x); }
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename... Args>
|
|
||||||
struct Overload : public Overload_helper<std::tuple<Args...>, std::tuple_size<std::tuple<Args...> >::value, Overload<Args...> >
|
|
||||||
{
|
|
||||||
typedef std::tuple<Args...> Tuple_type;
|
|
||||||
typedef typename std::tuple_element<0, Tuple_type>::type::result_type result_type;
|
|
||||||
|
|
||||||
|
|
||||||
Tuple_type t;
|
|
||||||
|
|
||||||
Overload(Args&&... args) : t(std::forward<Args>(args)...) {}
|
|
||||||
explicit Overload(const Tuple_type& t) : t(t) {}
|
|
||||||
|
|
||||||
Overload(Tuple_type&& t) : t(t) {}
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename... Args>
|
|
||||||
Overload<Args...> make_overload(Args&&... args) { return Overload<Args...>{ std::forward_as_tuple(args...) }; }
|
|
||||||
|
|
||||||
} // namespace CGAL
|
|
||||||
#endif // !defined(CGAL_CFG_NO_CPP0X_VARIADIC_TEMPLATES) && !defined(CGAL_CFG_NO_CPP0X_TUPLE)
|
|
||||||
|
|
||||||
#endif /* CGAL_OVERLOAD_H */
|
|
||||||
|
|
||||||
|
|
@ -1,49 +0,0 @@
|
||||||
#include <CGAL/compiler_config.h>
|
|
||||||
|
|
||||||
#if !defined(CGAL_CFG_NO_CPP0X_VARIADIC_TEMPLATES) && !defined(CGAL_CFG_NO_CPP0X_TUPLE)
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <tuple>
|
|
||||||
#include <functional>
|
|
||||||
#include <CGAL/Overload.h>
|
|
||||||
#include <CGAL/assertions.h>
|
|
||||||
#include <boost/variant.hpp>
|
|
||||||
|
|
||||||
|
|
||||||
void test_overload() {
|
|
||||||
using namespace CGAL;
|
|
||||||
using std::function;
|
|
||||||
|
|
||||||
auto t = std::make_tuple(function<int(int)>([](int) { return 1; }),
|
|
||||||
function<int(char)>([](char) { return 2; }),
|
|
||||||
function<int(double)>([](double) { return 3; }));
|
|
||||||
|
|
||||||
// manual construction
|
|
||||||
Overload<function<int(int)>, function<int(char)>, function<int(double)> > o2(t);
|
|
||||||
|
|
||||||
// basic overload checking
|
|
||||||
auto o = make_overload(function<int(int)>([](int) { return 1; }),
|
|
||||||
function<int(char)>([](char) { return 2; }),
|
|
||||||
function<int(double)>([](double) { return 3; }));
|
|
||||||
|
|
||||||
CGAL_assertion(o(1) == 1);
|
|
||||||
CGAL_assertion(o('a') == 2);
|
|
||||||
CGAL_assertion(o(2.0) == 3);
|
|
||||||
|
|
||||||
// check for variants
|
|
||||||
boost::variant<int, char, double> v1 = 1;
|
|
||||||
boost::variant<int, char, double> v2 = 'a';
|
|
||||||
boost::variant<int, char, double> v3 = 2.0;
|
|
||||||
|
|
||||||
CGAL_assertion(boost::apply_visitor(o, v1) == 1);
|
|
||||||
CGAL_assertion(boost::apply_visitor(o, v2) == 2);
|
|
||||||
CGAL_assertion(boost::apply_visitor(o, v3) == 3);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
#if !defined(CGAL_CFG_NO_CPP0X_VARIADIC_TEMPLATES) && !defined(CGAL_CFG_NO_CPP0X_TUPLE)
|
|
||||||
test_overload();
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue