Skip to content
Snippets Groups Projects
Commit 1a902a1e authored by Steffen Müthing's avatar Steffen Müthing
Browse files

Merge branch 'feature/FS1042-range-based-for-loops-test-and-iteratorrange'

This branch contains required infrastructure for the new iterator ranges
in dune-grid. In particular, it adds a configuration test that checks
whether the compiler supports range-based for loops and a small utility
class that serves as a container for a pair of begin and end iterators.

* feature/FS1042-range-based-for-loops-test-and-iteratorrange:
  [buildsystem] Check for range-based for.
  [Iterators] Add IteratorRange helper class
parents 05f43148 f5992f91
Branches
No related tags found
No related merge requests found
......@@ -9,6 +9,7 @@
# HAS_ATTRIBUTE_DEPRECATED_MSG True if attribute deprecated("msg") is supported
# HAVE_CONSTEXPR True if constexpr is supported
# HAVE_KEYWORD_FINAL True if final is supported.
# HAVE_RANGE_BASED_FOR True if range-based for is supported and working.
include(CMakePushCheckState)
cmake_push_check_state()
......@@ -166,4 +167,15 @@ check_cxx_source_compiles("
" HAVE_KEYWORD_FINAL
)
# range-based for
check_cxx_source_compiles("
int main(void)
{
int arr[3];
for(int &val : arr)
val = 0;
}
" HAVE_RANGE_BASED_FOR
)
cmake_pop_check_state()
......@@ -62,6 +62,7 @@ install(FILES
interfaces.hh
ios_state.hh
iteratorfacades.hh
iteratorrange.hh
lcm.hh
lru.hh
mallocallocator.hh
......
......@@ -58,6 +58,7 @@ commoninclude_HEADERS = \
interfaces.hh \
ios_state.hh \
iteratorfacades.hh \
iteratorrange.hh \
lcm.hh \
lru.hh \
mallocallocator.hh \
......
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#ifndef DUNE_COMMON_ITERATORRANGE_HH
#define DUNE_COMMON_ITERATORRANGE_HH
namespace Dune {
//! Simple range between a begin and an end iterator.
/**
* IteratorRange is mainly useful as a lightweight adaptor
* class when adding support for range-based for loops to
* existing containers that lack a standard begin(), end()
* pair of member functions.
*
* \tparam Iterator The type of iterator
*/
template<typename Iterator>
class IteratorRange
{
public:
//! The iterator belonging to this range.
typedef Iterator iterator;
//! Constructs an iterator range on [begin,end).
IteratorRange(const Iterator& begin, const Iterator& end)
: _begin(begin)
, _end(end)
{}
//! Returns an iterator pointing to the begin of the range.
iterator begin() const
{
return _begin;
}
//! Returns an iterator pointing past the end of the range.
iterator end() const
{
return _end;
}
private:
const Iterator _begin;
const Iterator _end;
};
}
#endif // DUNE_COMMON_ITERATORRANGE_HH
......@@ -11,6 +11,7 @@ install(PROGRAMS
cxx0x_nullptr.m4
cxx11_constexpr.m4
cxx11_final.m4
cxx11_range_based_for.m4
dune.m4
dune_all.m4
dune_autobuild.m4
......
......@@ -14,6 +14,7 @@ ALLM4S = \
cxx0x_nullptr.m4 \
cxx11_constexpr.m4 \
cxx11_final.m4 \
cxx11_range_based_for.m4 \
dune.m4 \
dune_all.m4 \
dune_autobuild.m4 \
......
# tests for C++11 range-based for support
# the associated define is called HAVE_RANGE_BASED_FOR
AC_DEFUN([DUNE_CXX11_RANGE_BASED_FOR],[
AC_CACHE_CHECK([for C++11 range-based for], [dune_cv_cxx11_range_based_for_support], [
AC_REQUIRE([AC_PROG_CXX])
AC_REQUIRE([CXX11])
AC_LANG_PUSH([C++])
AC_COMPILE_IFELSE([
AC_LANG_PROGRAM(,[[
int arr[3];
for(int &val : arr)
val = 0;
]])],
[dune_cv_cxx11_range_based_for_support=yes],
[dune_cv_cxx11_range_based_for_support=no])
AC_LANG_POP
])
if test "x$dune_cv_cxx11_range_based_for_support" = xyes; then
AC_DEFINE([HAVE_RANGE_BASED_FOR], [1], [Define to 1 if C++11 range-based for is supported])
fi
])
......@@ -21,6 +21,7 @@ AC_DEFUN([DUNE_COMMON_CHECKS],
AC_REQUIRE([CXX11])
AC_REQUIRE([NULLPTR_CHECK])
AC_REQUIRE([CXX11_CONSTEXPR_CHECK])
AC_REQUIRE([DUNE_CXX11_RANGE_BASED_FOR])
AC_REQUIRE([DUNE_BOOST_BASE])
AC_REQUIRE([DUNE_LINKCXX])
AC_REQUIRE([DUNE_CHECKDEPRECATED])
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment