Mercurial > hg > octave-lyh
changeset 14725:fa48fd0f160f
Add configure check for templated bitwise operators.
* m4/acinclude.m4 (OCTAVE_CXX_BITWISE_OP_TEMPLATES): New macro.
* configure.ac: Use it.
* src/bitfcns.cc: Define bit_and, bit_or and bit_xor if missing.
author | Carlo de Falco <cdf@users.sourceforge.net> |
---|---|
date | Tue, 05 Jun 2012 07:39:46 +0200 |
parents | 395d238418a7 |
children | baa10bd6f8df |
files | configure.ac m4/acinclude.m4 src/bitfcns.cc |
diffstat | 3 files changed, 44 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/configure.ac +++ b/configure.ac @@ -650,6 +650,7 @@ OCTAVE_IEEE754_DATA_FORMAT +OCTAVE_CXX_BITWISE_OP_TEMPLATES OCTAVE_CXX_COMPLEX_SETTERS OCTAVE_CXX_COMPLEX_REFERENCE_ACCESSORS
--- a/m4/acinclude.m4 +++ b/m4/acinclude.m4 @@ -105,6 +105,23 @@ AC_LANG_POP(C++) ]) dnl +dnl See if the C++ library has the bit_and, bit_or and bit_xor +dnl templates defined. +dnl +AC_DEFUN([OCTAVE_CXX_BITWISE_OP_TEMPLATES], +[AC_CACHE_CHECK([whether bit_and, bit_or and bit_xor are defined in the c++ library], +octave_cv_cxx_bitwise_op_templates, +[AC_LANG_PUSH(C++) +AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <functional>]], +[[double x = 0.0, y = 1.0; double z1 = bit_and<double> (x, y); double z2 = bit_or<double> (x, y); double z1 = bit_xor<double> (x, y);]])], +octave_cv_cxx_bitwise_op_templates=yes, octave_cv_cxx_bitwise_op_templates=no)]) +if test $octave_cv_cxx_bitwise_op_templates = yes; then +AC_DEFINE(HAVE_CXX_BITWISE_OP_TEMPLATES,1,[Define if C++ library has templated bitwise operators]) +fi +AC_LANG_POP(C++) +]) + +dnl dnl See if the C++ library has functions to set real and imaginary dnl parts of complex numbers independently. dnl
--- a/src/bitfcns.cc +++ b/src/bitfcns.cc @@ -44,6 +44,32 @@ #include <functional> +#if !defined (HAVE_CXX_BITWISE_OP_TEMPLATES) +namespace std +{ + template <typename T> + struct bit_and + { + public: + T operator() (const T & op1, const T & op2) const { return (op1 & op2); } + }; + + template <typename T> + struct bit_or + { + public: + T operator() (const T & op1, const T & op2) const { return (op1 | op2); } + }; + + template <typename T> + struct bit_xor + { + public: + T operator() (const T & op1, const T & op2) const { return (op1 ^ op2); } + }; +} +#endif + template <typename OP, typename T> octave_value bitopxx(const OP& op, const std::string& fname,