[Dune-devel] The file cxx11.hh

Oliver Sander sander at igpm.rwth-aachen.de
Tue Oct 1 10:45:44 CEST 2013


Am 01.10.2013 10:26, schrieb Christian Engwer:
> On Tue, Oct 01, 2013 at 10:20:20AM +0200, Martin Nolte wrote:
>> Hi Oli,
>>
>> I don't have a strong opinion on this. Feel free to rename the file
>> to constexpr.hh.
>>
>> However, my idea was to avoid cluttering dune-common with lots of
>> header files for c++11 compatiblity (we already have nullptr.hh,
>> staticassert.hh, ...). Therefore, I added 1 single header file that
>> should contain all those macros and other fallback stuff. It's just
>> a suggestion (the corresponding eMail was intended to follow later
>> today).
> 
> How about a subdirectory c++11 ?
> 
I wouldn't mind that.

--
Oliver


> Christian
> 
>> Best,
>>
>> Martin
>>
>> On 10/01/2013 10:00 AM, Oliver Sander wrote:
>>> Hi Martin,
>>> is cxx11.hh a good name for the file containing the constexpr wrapper?
>>> From the name alone I'd be hard-pressed to guess what it contains.
>>> Can we change the name to constexpr.hh?  That would be more consistent
>>> with unused.hh and deprecated.hh.
>>> Best,
>>> Oliver
>>>
>>> Am 01.10.2013 08:40, schrieb Martin Nolte:
>>>> New commit, appeared at Tue Oct  1 08:40:50 2013 +0200
>>>> as part of the following ref changes:
>>>>
>>>>     branch refs/heads/master    updated from b6e7446 -> 45990b6
>>>>
>>>> Browsable version: http://cgit.dune-project.org/repositories/dune-common/commit/?id=45990b699256890185c365419ef75c5c88c33f12
>>>>
>>>> ======================================================================
>>>>
>>>> commit 45990b699256890185c365419ef75c5c88c33f12
>>>> Author: Martin Nolte <nolte at mathematik.uni-freiburg.de>
>>>> Date:   Tue Oct 1 08:37:28 2013 +0200
>>>>
>>>>     [c++11] add support for C++11 constexpr
>>>>
>>>>     As decided on the developer meeting in Aachen, we support (but do not
>>>>     rely on) the C++11 keyword constexpr. This patch adds an m4-check for
>>>>     constexpr and a header (cxx11.hh) defining a macro DUNE_CONSTEXPR either
>>>>     as constexpr or empty (depending on the compiler support for it). It is
>>>>     then used in FieldVector and FieldMatrix on size, rows, and cols.
>>>>
>>>>  dune/common/CMakeLists.txt |  1 +
>>>>  dune/common/Makefile.am    |  1 +
>>>>  dune/common/cxx11.hh       | 10 ++++++++++
>>>>  dune/common/fmatrix.hh     |  9 +++++----
>>>>  dune/common/fvector.hh     | 10 ++++++++--
>>>>  m4/cxx11_constexpr.m4      | 28 ++++++++++++++++++++++++++++
>>>>  m4/dune_common.m4          |  1 +
>>>>  7 files changed, 54 insertions(+), 6 deletions(-)
>>>>  create mode 100644 dune/common/cxx11.hh
>>>>  create mode 100644 m4/cxx11_constexpr.m4
>>>>
>>>>
>>>>
>>>> diff --git a/dune/common/CMakeLists.txt b/dune/common/CMakeLists.txt
>>>> index 43fe8fc..f1dc93b 100644
>>>> --- a/dune/common/CMakeLists.txt
>>>> +++ b/dune/common/CMakeLists.txt
>>>> @@ -31,6 +31,7 @@ install(FILES
>>>>          bitsetvector.hh
>>>>          classname.hh
>>>>          collectivecommunication.hh
>>>> +        cxx11.hh
>>>>          debugallocator.hh
>>>>          debugstream.hh
>>>>          deprecated.hh
>>>> diff --git a/dune/common/Makefile.am b/dune/common/Makefile.am
>>>> index 75e9d54..9a645f6 100644
>>>> --- a/dune/common/Makefile.am
>>>> +++ b/dune/common/Makefile.am
>>>> @@ -28,6 +28,7 @@ commoninclude_HEADERS = 			\
>>>>  	bitsetvector.hh				\
>>>>  	classname.hh				\
>>>>  	collectivecommunication.hh		\
>>>> +	cxx11.hh				\
>>>>  	debugallocator.hh			\
>>>>  	debugstream.hh				\
>>>>  	deprecated.hh				\
>>>> diff --git a/dune/common/cxx11.hh b/dune/common/cxx11.hh
>>>> new file mode 100644
>>>> index 0000000..8ba3101
>>>> --- /dev/null
>>>> +++ b/dune/common/cxx11.hh
>>>> @@ -0,0 +1,10 @@
>>>> +#ifndef DUNE_COMMON_CXX11_HH
>>>> +#define DUNE_COMMON_CXX11_HH
>>>> +
>>>> +#if HAVE_CONSTEXPR
>>>> +#define DUNE_CONSTEXPR constexpr
>>>> +#else // #if HAVE_CONSTEXPR
>>>> +#define DUNE_CONSTEXPR
>>>> +#endif // #else // #if HAVE_CONSTEXPR
>>>> +
>>>> +#endif // #ifndef DUNE_COMMON_CXX11_HH
>>>> diff --git a/dune/common/fmatrix.hh b/dune/common/fmatrix.hh
>>>> index 826399e..adfdf61 100644
>>>> --- a/dune/common/fmatrix.hh
>>>> +++ b/dune/common/fmatrix.hh
>>>> @@ -8,6 +8,7 @@
>>>>  #include <cstddef>
>>>>  #include <iostream>
>>>>
>>>> +#include <dune/common/cxx11.hh>
>>>>  #include <dune/common/exceptions.hh>
>>>>  #include <dune/common/fvector.hh>
>>>>  #include <dune/common/densematrix.hh>
>>>> @@ -168,8 +169,8 @@ namespace Dune
>>>>      }
>>>>
>>>>      // make this thing a matrix
>>>> -    size_type mat_rows() const { return ROWS; }
>>>> -    size_type mat_cols() const { return COLS; }
>>>> +    DUNE_CONSTEXPR size_type mat_rows() const { return ROWS; }
>>>> +    DUNE_CONSTEXPR size_type mat_cols() const { return COLS; }
>>>>
>>>>      row_reference mat_access ( size_type i )
>>>>      {
>>>> @@ -270,8 +271,8 @@ namespace Dune
>>>>      }
>>>>
>>>>      // make this thing a matrix
>>>> -    size_type mat_rows() const { return 1; }
>>>> -    size_type mat_cols() const { return 1; }
>>>> +    DUNE_CONSTEXPR size_type mat_rows() const { return 1; }
>>>> +    DUNE_CONSTEXPR size_type mat_cols() const { return 1; }
>>>>
>>>>      row_reference mat_access ( size_type i )
>>>>      {
>>>> diff --git a/dune/common/fvector.hh b/dune/common/fvector.hh
>>>> index 6084355..4d113c8 100644
>>>> --- a/dune/common/fvector.hh
>>>> +++ b/dune/common/fvector.hh
>>>> @@ -11,6 +11,8 @@
>>>>  #include <cstring>
>>>>  #include <utility>
>>>>
>>>> +#include <dune/common/cxx11.hh>
>>>> +
>>>>  #include "typetraits.hh"
>>>>  #include "exceptions.hh"
>>>>  #include "array.hh"
>>>> @@ -156,8 +158,10 @@ namespace Dune {
>>>>      }
>>>>      using Base::operator=;
>>>>
>>>> +    DUNE_CONSTEXPR size_type size () const { return vec_size(); }
>>>> +
>>>>      // make this thing a vector
>>>> -    size_type vec_size() const { return SIZE; }
>>>> +    DUNE_CONSTEXPR size_type vec_size () const { return SIZE; }
>>>>      K & vec_access(size_type i) { return _data[i]; }
>>>>      const K & vec_access(size_type i) const { return _data[i]; }
>>>>    private:
>>>> @@ -243,8 +247,10 @@ namespace Dune {
>>>>        return *this;
>>>>      }
>>>>
>>>> +    DUNE_CONSTEXPR size_type size () const { return vec_size(); }
>>>> +
>>>>      //===== forward methods to container
>>>> -    size_type vec_size() const { return 1; }
>>>> +    DUNE_CONSTEXPR size_type vec_size () const { return 1; }
>>>>      K & vec_access(size_type i)
>>>>      {
>>>>        assert(i == 0);
>>>> diff --git a/m4/cxx11_constexpr.m4 b/m4/cxx11_constexpr.m4
>>>> new file mode 100644
>>>> index 0000000..12b7b7a
>>>> --- /dev/null
>>>> +++ b/m4/cxx11_constexpr.m4
>>>> @@ -0,0 +1,28 @@
>>>> +# tests for C++11 constexpr support
>>>> +# the associated macro is called HAVE_CONSTEXPR
>>>> +
>>>> +AC_DEFUN([CXX11_CONSTEXPR_CHECK],[
>>>> +  AC_CACHE_CHECK([for C++11 constexpr], dune_cv_cxx11_constexpr_support, [
>>>> +    AC_REQUIRE([AC_PROG_CXX])
>>>> +    AC_REQUIRE([GXX0X])
>>>> +    AC_LANG_PUSH([C++])
>>>> +    AC_COMPILE_IFELSE([
>>>> +      AC_LANG_PROGRAM([
>>>> +          constexpr int foo () { return 0; }
>>>> +
>>>> +          template< int v >
>>>> +          struct A
>>>> +          {
>>>> +            static const int value = v;
>>>> +          };
>>>> +        ],[
>>>> +          return A< foo() >::value;
>>>> +        ])],
>>>> +      dune_cv_cxx11_constexpr_support=yes,
>>>> +      dune_cv_cxx11_constexpr_support=no)
>>>> +    AC_LANG_POP
>>>> +  ])
>>>> +  if test "x$dune_cv_cxx11_constexpr_support" = xyes; then
>>>> +    AC_DEFINE(HAVE_CONSTEXPR, 1, [Define to 1 if C++11 constexpr is supported])
>>>> +  fi
>>>> +])
>>>> diff --git a/m4/dune_common.m4 b/m4/dune_common.m4
>>>> index d9debce..5b13851 100644
>>>> --- a/m4/dune_common.m4
>>>> +++ b/m4/dune_common.m4
>>>> @@ -26,6 +26,7 @@ AC_DEFUN([DUNE_COMMON_CHECKS],
>>>>    AC_REQUIRE([RVALUE_REFERENCES_CHECK])
>>>>    AC_REQUIRE([INITIALIZER_LIST_CHECK])
>>>>    AC_REQUIRE([CXX11_CONDITIONAL_CHECK])
>>>> +  AC_REQUIRE([CXX11_CONSTEXPR_CHECK])
>>>>    AC_REQUIRE([DUNE_BOOST_BASE])
>>>>    AC_REQUIRE([MAKE_SHARED])
>>>>    AC_REQUIRE([DUNE_LINKCXX])
>>>>
>>>> _______________________________________________
>>>> Dune-Commit mailing list
>>>> Dune-Commit at dune-project.org
>>>> http://lists.dune-project.org/mailman/listinfo/dune-commit
>>>>
>>>
>>>
>>>
>>>
>>> _______________________________________________
>>> Dune-devel mailing list
>>> Dune-devel at dune-project.org
>>> http://lists.dune-project.org/mailman/listinfo/dune-devel
>>>
>>
>> -- 
>> Dr. Martin Nolte <nolte at mathematik.uni-freiburg.de>
>>
>> Universität Freiburg                                   phone: +49-761-203-5630
>> Abteilung für angewandte Mathematik                    fax:   +49-761-203-5632
>> Hermann-Herder-Straße 10
>> 79104 Freiburg, Germany
>>
>> _______________________________________________
>> Dune-devel mailing list
>> Dune-devel at dune-project.org
>> http://lists.dune-project.org/mailman/listinfo/dune-devel
>>
> 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 551 bytes
Desc: OpenPGP digital signature
URL: <https://lists.dune-project.org/pipermail/dune-devel/attachments/20131001/99e2f9b2/attachment.sig>


More information about the Dune-devel mailing list