# HG changeset patch
# User Carlo de Falco
# Date 1337965068 -7200
# Node ID f1bbfcc153897dbfd78a898bc333d54e1877249e
# Parent 57e4ff70b7c1e3e7bcc798706a6a85319300bbc2
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.
diff --git a/configure.ac b/configure.ac
--- 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
diff --git a/m4/acinclude.m4 b/m4/acinclude.m4
--- 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 ]],
+[[double x = 0.0, y = 1.0; double z1 = bit_and (x, y); double z2 = bit_or (x, y); double z1 = bit_xor (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
diff --git a/src/bitfcns.cc b/src/bitfcns.cc
--- a/src/bitfcns.cc
+++ b/src/bitfcns.cc
@@ -44,6 +44,32 @@
#include
+#if !defined (HAVE_CXX_BITWISE_OP_TEMPLATES)
+namespace std
+{
+ template
+ struct bit_and
+ {
+ public:
+ T operator() (const T & op1, const T & op2) const { return (op1 & op2); }
+ };
+
+ template
+ struct bit_or
+ {
+ public:
+ T operator() (const T & op1, const T & op2) const { return (op1 | op2); }
+ };
+
+ template
+ struct bit_xor
+ {
+ public:
+ T operator() (const T & op1, const T & op2) const { return (op1 ^ op2); }
+ };
+}
+#endif
+
template
octave_value
bitopxx(const OP& op, const std::string& fname,