Skip to content
Snippets Groups Projects
Commit 8d981b1f authored by Oliver Sander's avatar Oliver Sander
Browse files

Add a mechanism for the transition from FieldVector::size as an enum member

to FieldVector::size() as a method.

With this patch applied FieldVector::size remains an enum, hence all your
code compiles as before.  However you get a compiler warning explaining
the issue and suggesting to configure with --enable-fieldvector-size-is-method.
If you do so, then FieldVector::size becomes a method, and you may have
to go out and adjust your code.  The configure flag is transitional and
will be removed after dune 2.2 is out.

Remember that there is no smoother way to do the transition, as you can't
have FieldVector::size to be both an enum value and a method at the same
time.

This fixes FlySpray issue 819.


[[Imported from SVN: r6486]]
parent 7235499a
No related branches found
No related tags found
No related merge requests found
......@@ -15,6 +15,15 @@
#include "densevector.hh"
#include "static_assert.hh"
#if ! DUNE_COMMON_FIELDVECTOR_SIZE_IS_METHOD
#warning The FieldVector class exports is size by the enum member 'size'.\
This behavior is deprecated. In the future, 'size' will be a method,\
which puts it in compliance with the stl conventions. To enable the new behavior\
(and get rid of this warning), build your Dune with --enable-fieldvector-size-is-method.\
If you do need the vector size as an enum, use 'dimension'.
#endif
namespace Dune {
/** @addtogroup DenseMatVec
......@@ -58,9 +67,12 @@ namespace Dune {
//! export size
enum {
//! The size of this vector.
dimension = SIZE,
dimension = SIZE
#if ! DUNE_COMMON_FIELDVECTOR_SIZE_IS_METHOD
,
//! The size of this vector.
size = SIZE
#endif
};
typedef typename Base::size_type size_type;
......@@ -154,9 +166,12 @@ namespace Dune {
//! export size
enum {
//! The size of this vector.
dimension = 1,
dimension = 1
#if ! DUNE_COMMON_FIELDVECTOR_SIZE_IS_METHOD
,
//! The size of this vector.
size = 1
#endif
};
typedef typename Base::size_type size_type;
......
......@@ -90,6 +90,12 @@ struct FieldVectorMainTest
}
s >> w;
assert(v == w);
// test container methods
typename FieldVector<ft,d>::size_type size = FieldVector<ft,d>::dimension;
#if DUNE_COMMON_FIELDVECTOR_SIZE_IS_METHOD
size = w.size();
#endif
}
};
......
......@@ -31,6 +31,11 @@ AC_DEFUN([DUNE_COMMON_CHECKS],
AC_REQUIRE([DUNE_EXPRTMPL])
AC_REQUIRE([DUNE_TR1_HEADERS])
dnl Create the flag --enable-fieldvector-size-is-method
dnl This is to orchestrate the transition from the constant member FieldVector::size
dnl to the method FieldVector::size()
AC_REQUIRE([DUNE_FIELDVECTOR_SIZE_IS_METHOD])
dnl check for programs
AC_REQUIRE([AC_PROG_CC])
# add -Wall if the compiler is gcc
......
dnl This macro introduces a configure flag --enable-fieldvector-size-is method
dnl that is used to orchestrate the transition from FieldVector::size as an enum
dnl and FieldVector::size() as a method (see FS 819 for details).
dnl If this flag is not set (the default), then FieldVector::size is an enum,
dnl but a compiler warning appears. If it is set then the warning disappears,
dnl but FieldVector::size() becomes a method.
dnl
dnl This flag and the corresponding preprocessor directives should be removed
dnl not earlier than after dune-2.2 has been released.
AC_DEFUN([DUNE_FIELDVECTOR_SIZE_IS_METHOD],[
AC_ARG_ENABLE(fieldvector-size-is-method,
AS_HELP_STRING([--enable-fieldvector-size-is-method],[If this is set, the member 'size' of FieldVector is a method rather than an enum]))
AS_IF([test "x$enable_fieldvector_size_is_method" = "xyes"],
AC_DEFINE(DUNE_COMMON_FIELDVECTOR_SIZE_IS_METHOD, 1, [If this is set, the member 'size' of FieldVector is a method rather than an enum]))
])
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment