Skip to content

Commit

Permalink
Added compile time checks that T = iterator::value_type
Browse files Browse the repository at this point in the history
  • Loading branch information
k7miller committed May 29, 2018
1 parent c21e42c commit 1c130c9
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions include/DenseMatrixHelpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
#include <blitz/array.h>
#include <cmath>
#include <cstddef>
#include <iterator>
#include <limits>
#include <stdexcept>
#include <type_traits>

namespace blitzdg {
/**
Expand Down Expand Up @@ -83,6 +85,11 @@ namespace blitzdg {
*/
template <typename T, typename OutputItr>
void fullToPodArray(const matrix_type<T>& mat, OutputItr arrItr, bool byRows = true) {
// Fail at compile time if the type T is not
// the same as the value type of OutputItr.
static_assert(std::is_same<T,
typename std::iterator_traits<OutputItr>::value_type>::value,
"Matrix value type differs from array value type");
if (byRows) {
for (index_type i = 0; i < mat.rows(); ++i) {
for (index_type j = 0; j < mat.cols(); ++j)
Expand All @@ -108,6 +115,11 @@ namespace blitzdg {
*/
template <typename T, typename InputItr>
void podArrayToFull(InputItr arrItr, matrix_type<T>& mat, bool byRows = true) {
// Fail at compile time if the type T is not
// the same as the value type of InputItr.
static_assert(std::is_same<T,

This comment has been minimized.

Copy link
@dsteinmo

dsteinmo May 29, 2018

Member

Nice, didn't know this was a thing!

typename std::iterator_traits<InputItr>::value_type>::value,
"Matrix value type differs from array value type");
if (byRows) {
for (index_type i = 0; i < mat.rows(); ++i) {
for (index_type j = 0; j < mat.cols(); ++j)
Expand Down

0 comments on commit 1c130c9

Please sign in to comment.