]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Use std::conditional instead of a switch class. 7097/head
authorWolfgang Bangerth <bangerth@colostate.edu>
Tue, 21 Aug 2018 21:55:04 +0000 (15:55 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Tue, 21 Aug 2018 21:55:04 +0000 (15:55 -0600)
include/deal.II/lac/block_vector_base.h

index d2b521755463ec81aa6f3db1e5224cf082dbe40a..b9ab9d8308e490027bc07b5a207d05d7e7cf76ed 100644 (file)
@@ -115,87 +115,6 @@ namespace internal
    */
   namespace BlockVectorIterators
   {
-    /**
-     * Declaration of the general template of a structure which is used to
-     * determine some types based on the template arguments of other classes.
-     */
-    template <class BlockVectorType, bool Constness>
-    struct Types
-    {};
-
-
-
-    /**
-     * Declaration of a specialized template of a structure which is used to
-     * determine some types based on the template arguments of other classes.
-     *
-     * This is for the use of non-const iterators.
-     */
-    template <class BlockVectorType>
-    struct Types<BlockVectorType, false>
-    {
-      /**
-       * Type of the vector underlying the block vector used in non-const
-       * iterators. There, the vector must not be constant.
-       */
-      using Vector = typename BlockVectorType::BlockType;
-
-      /**
-       * Type of the block vector used in non-const iterators. There, the
-       * block vector must not be constant.
-       */
-      using BlockVector = BlockVectorType;
-
-      /**
-       * Type of the numbers we point to. Here, they are not constant.
-       */
-      using value_type = typename BlockVector::value_type;
-
-      /**
-       * Typedef the result of a dereferencing operation for an iterator of
-       * the underlying iterator.
-       */
-      using dereference_type = typename Vector::reference;
-    };
-
-
-
-    /**
-     * Declaration of a specialized template of a structure which is used to
-     * determine some types based on the template arguments of other classes.
-     *
-     * This is for the use of const_iterator.
-     */
-    template <class BlockVectorType>
-    struct Types<BlockVectorType, true>
-    {
-      /**
-       * Type of the vector underlying the block vector used in
-       * const_iterator. There, the vector must be constant.
-       */
-      using Vector = const typename BlockVectorType::BlockType;
-
-      /**
-       * Type of the block vector used in const_iterator. There, the block
-       * vector must be constant.
-       */
-      using BlockVector = const BlockVectorType;
-
-      /**
-       * Type of the numbers we point to. Here, they are constant since the
-       * block vector we use is constant.
-       */
-      using value_type = const typename BlockVector::value_type;
-
-      /**
-       * Typedef the result of a dereferencing operation for an iterator of
-       * the underlying iterator. Since this is for constant iterators, we can
-       * only return values, not actual references.
-       */
-      using dereference_type = value_type;
-    };
-
-
     /**
      * General random-access iterator class for block vectors. Since we do not
      * want to have two classes for non-const iterator and const_iterator, we
@@ -227,7 +146,10 @@ namespace internal
        * the second template parameter, this is either a constant or non-const
        * number.
        */
-      using value_type = typename Types<BlockVectorType, Constness>::value_type;
+      using value_type =
+        typename std::conditional<Constness,
+                                  const typename BlockVectorType::value_type,
+                                  typename BlockVectorType::value_type>::type;
 
       /**
        * Declare some alias which are standard for iterators and are used
@@ -239,15 +161,17 @@ namespace internal
       using reference         = typename BlockVectorType::reference;
       using pointer           = value_type *;
 
-      using dereference_type =
-        typename Types<BlockVectorType, Constness>::dereference_type;
+      using dereference_type = typename std::conditional<
+        Constness,
+        value_type,
+        typename BlockVectorType::BlockType::reference>::type;
 
       /**
        * Typedef the type of the block vector (which differs in constness,
        * depending on the second template parameter).
        */
-      using BlockVector =
-        typename Types<BlockVectorType, Constness>::BlockVector;
+      using BlockVector = typename std::
+        conditional<Constness, const BlockVectorType, BlockVectorType>::type;
 
       /**
        * Construct an iterator from a vector to which we point and the global

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.