valarray_meta.h (__unary_plus, [...]): New function object classes.

* include/bits/valarray_meta.h (__unary_plus, __negate,
	__bitwise_not, __plus, __minus, __multiplies, __divides,
	__modulus, __bitwise_xor, __bitwise_or, __bitwise_and,
	__shift_left, __shift_right, __logical_and, __logical_or,
	__logical_not, __equal_to, __not_equal_to, __less, __less_equal,
	__greater_equal, __greater, __atan2, __pow): New function object
	classes.
	(__fun<>):  New function traits class.

From-SVN: r55985
This commit is contained in:
Gabriel Dos Reis 2002-08-02 13:51:46 +00:00 committed by Gabriel Dos Reis
parent a77a9a18c0
commit 2b1a407046
2 changed files with 245 additions and 0 deletions

View File

@ -1,3 +1,14 @@
2002-08-02 Gabriel Dos Reis <gdr@nerim.net>
* include/bits/valarray_meta.h (__unary_plus, __negate,
__bitwise_not, __plus, __minus, __multiplies, __divides,
__modulus, __bitwise_xor, __bitwise_or, __bitwise_and,
__shift_left, __shift_right, __logical_and, __logical_or,
__logical_not, __equal_to, __not_equal_to, __less, __less_equal,
__greater_equal, __greater, __atan2, __pow): New function object
classes.
(__fun<>): New function traits class.
2002-08-01 Rick Danos <rdanos@hotmail.com>
PR libstdc++/7461

View File

@ -165,6 +165,240 @@ namespace std
_Tp operator()(const _Tp& __t) const { return sqrt(__t); }
};
// In the past, we used to tailor operator applications semantics
// to the specialization of standard function objects (i.e. plus<>, etc.)
// That is incorrect. Therefore we provide our own surrogates.
struct __unary_plus
{
template<typename _Tp>
_Tp operator()(const _Tp& __t) const { return +__t; }
};
struct __negate
{
template<typename _Tp>
_Tp operator()(const _Tp& __t) const { return -__t; }
};
struct __bitwise_not
{
template<typename _Tp>
_Tp operator()(const _Tp& __t) const { return ~__t; }
};
struct __plus
{
template<typename _Tp>
_Tp operator()(const _Tp& __x, const _Tp& __y) const
{ return __x + __y; }
};
struct __minus
{
template<typename _Tp>
_Tp operator()(const _Tp& __x, const _Tp& __y) const
{ return __x - __y; }
};
struct __multiplies
{
template<typename _Tp>
_Tp operator()(const _Tp& __x, const _Tp& __y) const
{ return __x * __y; }
};
struct __divides
{
template<typename _Tp>
_Tp operator()(const _Tp& __x, const _Tp& __y) const
{ return __x / __y; }
};
struct __modulus
{
template<typename _Tp>
_Tp operator()(const _Tp& __x, const _Tp& __y) const
{ return __x % __y; }
};
struct __bitwise_xor
{
template<typename _Tp>
_Tp operator()(const _Tp& __x, const _Tp& __y) const
{ return __x ^ __y; }
};
struct __bitwise_and
{
template<typename _Tp>
_Tp operator()(const _Tp& __x, const _Tp& __y) const
{ return __x & __y; }
};
struct __bitwise_or
{
template<typename _Tp>
_Tp operator()(const _Tp& __x, const _Tp& __y) const
{ return __x | __y; }
};
struct __shift__left
{
template<typename _Tp>
_Tp operator()(const _Tp& __x, const _Tp& __y) const
{ return __x << __y; }
};
struct __shift_right
{
template<typename _Tp>
_Tp operator()(const _Tp& __x, const _Tp& __y) const
{ return __x >> __y; }
};
struct __logical_and
{
template<typename _Tp>
bool operator()(const _Tp& __x, const _Tp& __y) const
{ return __x && __y; }
};
struct __logical_or
{
template<typename _Tp>
bool operator()(const _Tp& __x, const _Tp& __y) const
{ return __x || __y; }
};
struct __logical_not
{
template<typename _Tp>
bool operator()(const _Tp& __x) const { return !__x; }
};
struct __equal_to
{
template<typename _Tp>
bool operator()(const _Tp& __x, const _Tp& __y) const
{ return __x == __y; }
};
struct __not_equal_to
{
template<typename _Tp>
bool operator()(const _Tp& __x, const _Tp& __y) const
{ return __x == __y; }
};
struct __less
{
template<typename _Tp>
bool operator()(const _Tp& __x, const _Tp& __y) const
{ return __x < __y; }
};
struct __greater
{
template<typename _Tp>
bool operator()(const _Tp& __x, const _Tp& __y) const
{ return __x > __y; }
};
struct __less_equal
{
template<typename _Tp>
bool operator()(const _Tp& __x, const _Tp& __y) const
{ return __x <= __y; }
};
struct __greater_equal
{
template<typename _Tp>
bool operator()(const _Tp& __x, const _Tp& __y) const
{ return __x >= __y; }
};
// The few binary functions we miss.
struct __atan2
{
template<typename _Tp>
_Tp operator()(const _Tp& __x, const _Tp& __y) const
{ return atan2(__x, __y); }
};
struct __pow
{
template<typename _Tp>
_Tp operator()(const _Tp& __x, const _Tp& __y) const
{ return pow(__x, __y); }
};
// We need these bits in order to recover the return type of
// some functions/operators now that we're no longer using
// function templates.
template<typename, typename _Tp>
struct __fun
{
typedef _Tp result_type;
};
// several specializations for relational operators.
template<typename _Tp>
struct __fun<__logical_not, _Tp>
{
typedef bool result_type;
};
template<typename _Tp>
struct __fun<__logical_and, _Tp>
{
typedef bool result_type;
};
template<typename _Tp>
struct __fun<__logical_or, _Tp>
{
typedef bool result_type;
};
template<typename _Tp>
struct __fun<__less, _Tp>
{
typedef bool result_type;
};
template<typename _Tp>
struct __fun<__greater, _Tp>
{
typedef bool result_type;
};
template<typename _Tp>
struct __fun<__less_equal, _Tp>
{
typedef bool result_type;
};
template<typename _Tp>
struct __fun<__greater_equal, _Tp>
{
typedef bool result_type;
};
template<typename _Tp>
struct __fun<__equal_to, _Tp>
{
typedef bool result_type;
};
template<typename _Tp>
struct __fun<__not_equal_to, _Tp>
{
typedef bool result_type;
};
template<template<class, class> class _Meta, class _Dom, typename _Op>
class _UnFunClos;