Boost logo

Boost-Commit :

From: garcia_at_[hidden]
Date: 2008-07-24 15:10:40


Author: garcia
Date: 2008-07-24 15:10:40 EDT (Thu, 24 Jul 2008)
New Revision: 47768
URL: http://svn.boost.org/trac/boost/changeset/47768

Log:
Initial Revision.

Added:
   trunk/libs/multi_array/example/resize_from_other.cpp (contents, props changed)

Added: trunk/libs/multi_array/example/resize_from_other.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/multi_array/example/resize_from_other.cpp 2008-07-24 15:10:40 EDT (Thu, 24 Jul 2008)
@@ -0,0 +1,57 @@
+// Copyright 2008 The Trustees of Indiana University.
+
+// Use, modification and distribution is subject to the Boost Software
+// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+// Boost.MultiArray Library
+// Authors: Ronald Garcia
+// Jeremy Siek
+// Andrew Lumsdaine
+// See http://www.boost.org/libs/multi_array for documentation.
+
+//
+// resize_from_other.cpp - an experiment in writing a resize function for
+// multi_arrays that will use the extents from another to build itself.
+//
+
+#include <boost/multi_array.hpp>
+#include <boost/static_assert.hpp>
+#include <boost/array.hpp>
+#include <algorithm>
+
+template <typename T, typename U, std::size_t N>
+void
+resize_from_MultiArray(boost::multi_array<T,N>& marray, U& other) {
+
+ // U must be a model of MultiArray
+ boost::function_requires<
+ boost::detail::multi_array::ConstMultiArrayConcept<U,U::dimensionality> >();
+ // U better have U::dimensionality == N
+ BOOST_STATIC_ASSERT(U::dimensionality == N);
+
+ boost::array<typename boost::multi_array<T,N>::size_type, N> shape;
+
+ std::copy(other.shape(), other.shape()+N, shape.begin());
+
+ marray.resize(shape);
+
+}
+
+#include <iostream>
+
+
+int main () {
+
+ boost::multi_array<int,2> A(boost::extents[5][4]), B;
+ boost::multi_array<int,3> C;
+
+ resize_from_MultiArray(B,A);
+
+#if 0
+ resize_from_MultiArray(C,A); // Compile-time error
+#endif
+
+ std::cout << B.shape()[0] << ", " << B.shape()[1] << '\n';
+
+}


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk