valarray_before.h

来自「symbian上STL模板库的实现」· C头文件 代码 · 共 702 行 · 第 1/2 页

H
702
字号
// The template and inlines for the -*- C++ -*- internal _Meta class.// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.//// This file is part of the GNU ISO C++ Library.  This library is free// software; you can redistribute it and/or modify it under the// terms of the GNU General Public License as published by the// Free Software Foundation; either version 2, or (at your option)// any later version.// This library is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the// GNU General Public License for more details.// You should have received a copy of the GNU General Public License along// with this library; see the file COPYING.  If not, write to the Free// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,// USA.// As a special exception, you may use this file as part of a free software// library without restriction.  Specifically, if other files instantiate// templates or use macros or inline functions from this file, or you compile// this file and link it with other files to produce an executable, this// file does not by itself cause the resulting executable to be covered by// the GNU General Public License.  This exception does not however// invalidate any other reasons why the executable file might be covered by// the GNU General Public License.// Written by Gabriel Dos Reis <Gabriel.Dos-Reis@cmla.ens-cachan.fr>/** @file valarray_meta.h *  This is an internal header file, included by other library headers. *  You should not attempt to use it directly. */#ifndef _VALARRAY_BEFORE_H#define _VALARRAY_BEFORE_H 1//#pragma GCC system_header#include <bits/slice_array.h>namespace std{    //    // Implementing a loosened valarray return value is tricky.    // First we need to meet 26.3.1/3: we should not add more than    // two levels of template nesting. Therefore we resort to template    // template to "flatten" loosened return value types.    // At some point we use partial specialization to remove one level    // template nesting due to _Expr<>    //    // This class is NOT defined. It doesn't need to.    template<typename _Tp1, typename _Tp2> class _Constant;    // Implementations of unary functions applied to valarray<>s.    // I use hard-coded object functions here instead of a generic    // approach like pointers to function:    //    1) correctness: some functions take references, others values.    //       we can't deduce the correct type afterwards.    //    2) efficiency -- object functions can be easily inlined    //    3) be Koenig-lookup-friendly    struct __abs    {        template<typename _Tp>            _Tp operator()(const _Tp& __t) const { return abs(__t); }    };    struct __cos    {        template<typename _Tp>            _Tp operator()(const _Tp& __t) const { return cos(__t); }    };    struct __acos    {        template<typename _Tp>            _Tp operator()(const _Tp& __t) const { return acos(__t); }    };    struct __cosh    {        template<typename _Tp>            _Tp operator()(const _Tp& __t) const { return cosh(__t); }    };    struct __sin    {        template<typename _Tp>            _Tp operator()(const _Tp& __t) const { return sin(__t); }    };    struct __asin    {        template<typename _Tp>            _Tp operator()(const _Tp& __t) const { return asin(__t); }    };    struct __sinh    {        template<typename _Tp>            _Tp operator()(const _Tp& __t) const { return sinh(__t); }    };    struct __tan    {        template<typename _Tp>            _Tp operator()(const _Tp& __t) const { return tan(__t); }    };    struct __atan    {        template<typename _Tp>            _Tp operator()(const _Tp& __t) const { return atan(__t); }    };    struct __tanh    {        template<typename _Tp>            _Tp operator()(const _Tp& __t) const { return tanh(__t); }    };    struct __exp    {        template<typename _Tp>            _Tp operator()(const _Tp& __t) const { return exp(__t); }    };    struct __log    {        template<typename _Tp>            _Tp operator()(const _Tp& __t) const { return log(__t); }    };    struct __log10    {        template<typename _Tp>            _Tp operator()(const _Tp& __t) const { return log10(__t); }    };    struct __sqrt    {        template<typename _Tp>            _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;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?