diff --git a/dune/common/fvector.hh b/dune/common/fvector.hh index 9dbfd8c0a6dbf5a6a6861ebe646c89718ca6fc08..82a4bd3f0c1b9da7597eefb15453a640229cac2f 100644 --- a/dune/common/fvector.hh +++ b/dune/common/fvector.hh @@ -13,6 +13,7 @@ #include "exceptions.hh" #include "array.hh" #include "densevector.hh" +#include "static_assert.hh" namespace Dune { @@ -87,6 +88,14 @@ namespace Dune { _data[i] = x[i]; } + //! Constructor making vector with identical coordinates + template<class K1, int SIZE1> + explicit FieldVector (const FieldVector<K1,SIZE1> & x) + { + static_assert(SIZE1 == SIZE, "FieldVector in costructor has wrong size"); + for (size_type i = 0; i<SIZE; i++) + _data[i] = x[i]; + } using Base::operator=; // make this thing a vector diff --git a/dune/common/test/.gitignore b/dune/common/test/.gitignore index 6c54da3f78c7e2c065508151d674d652c67e5ead..f77f293b17d439eb10c370c8823c33d2f377e779 100644 --- a/dune/common/test/.gitignore +++ b/dune/common/test/.gitignore @@ -60,3 +60,4 @@ tags pathtest TAGS mpihelpertest2 +testfconstruct diff --git a/dune/common/test/Makefile.am b/dune/common/test/Makefile.am index b487dd4bf7a25cae0507e3b69462f5bacd4d8510..3e76afae73650638d8224307e4472f153d046480 100644 --- a/dune/common/test/Makefile.am +++ b/dune/common/test/Makefile.am @@ -43,6 +43,7 @@ TESTPROGS = \ testfassign_fail4 \ testfassign_fail5 \ testfassign_fail6 \ + testfconstruct \ tuplestest_dune \ tuplestest_std \ tuplestest_tr1 \ @@ -52,7 +53,7 @@ TESTPROGS = \ # which tests to run COMPILE_XFAIL=$(DUNE_COMMON_BIN)/xfail-compile-tests -COMPILE_XFAIL_TESTS = genericiterator_compile_fail nullptr-test-fail static_assert_test_fail +COMPILE_XFAIL_TESTS = genericiterator_compile_fail nullptr-test-fail static_assert_test_fail testfconstruct_fail1 testfconstruct_fail2 compile_XFAIL: for i in $(COMPILE_XFAIL_TESTS); do \ @@ -200,6 +201,15 @@ testfassign_fail5_CPPFLAGS = $(AM_CPPFLAGS) -D_N=2 -D_M=2 -D_VALUES="1, 2" testfassign_fail6_SOURCES = testfassign.cc testfassign_fail6_CPPFLAGS = $(AM_CPPFLAGS) -D_N=2 -D_M=2 -D_VALUES="1, 2, nextRow, 2, 3, nextRow, 4, 5" +testfconstruct_SOURCES = testfconstruct.cc +testfconstruct_CPPFLAGS = $(AM_CPPFLAGS) -DFVSIZE=3 + +testfconstruct_fail1_SOURCES = testfconstruct.cc +testfconstruct_fail1_CPPFLAGS = $(AM_CPPFLAGS) -DFVSIZE=2 + +testfconstruct_fail2_SOURCES = testfconstruct.cc +testfconstruct_fail2_CPPFLAGS = $(AM_CPPFLAGS) -DFVSIZE=5 + conversiontest_SOURCES = conversiontest.cc sourcescheck_NOSOURCES = exprtmpl.cc timing.cc diff --git a/dune/common/test/testfconstruct.cc b/dune/common/test/testfconstruct.cc new file mode 100644 index 0000000000000000000000000000000000000000..b24370cd206eebde5b6e34b385121f85e6007b96 --- /dev/null +++ b/dune/common/test/testfconstruct.cc @@ -0,0 +1,17 @@ +// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- +// vi: set et ts=4 sw=2 sts=2: +#include <config.h> + +#include <iostream> +#include <dune/common/fvector.hh> +#include <dune/common/fassign.hh> + +using namespace Dune; + +int main(int argc, char** argv) { + Dune::FieldVector<double,3> pos; + + pos <<= 1, 0, 0; + + Dune::FieldVector<float,FVSIZE> pos2(pos); +}