MADNESS 0.10.1
array_addons.h
Go to the documentation of this file.
1/*
2 This file is part of MADNESS.
3
4 Copyright (C) 2007,2010 Oak Ridge National Laboratory
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
20 For more information please contact:
21
22 Robert J. Harrison
23 Oak Ridge National Laboratory
24 One Bethel Valley Road
25 P.O. Box 2008, MS-6367
26
27 email: harrisonrj@ornl.gov
28 tel: 865-241-3937
29 fax: 865-572-0680
30*/
31
32#ifndef MADNESS_WORLD_ARRAY_ADDONS_H__INCLUDED
33#define MADNESS_WORLD_ARRAY_ADDONS_H__INCLUDED
34
35/**
36 \file array_addons.h
37 \brief Supplements to the \c std::array class, such as I/O operations,
38 for convenience.
39 \ingroup containers
40*/
41
45#include <array>
46#include <iostream>
47
48namespace madness {
49
50 namespace operators {
51 /// Output \c std::array to stream for human consumption.
52
53 /// \tparam T The type of data stored in the array.
54 /// \tparam N The size of the array.
55 /// \param[in,out] s The output stream.
56 /// \param[in] a The array to be output.
57 /// \return The output stream.
58 template <typename T, std::size_t N>
59 std::ostream &operator<<(std::ostream &s, const std::array<T, N> &a) {
60 s << "[";
61 for (std::size_t i = 0; i < N; ++i) {
62 s << a[i];
63 if (i != (N - 1))
64 s << ",";
65 }
66 s << "]";
67 return s;
68}
69 } // namespace operators
70
71 /// Hash std::array with madness hash.
72
73 /// \tparam T The type of data stored in the array.
74 /// \tparam N The size of the array.
75 /// \param[in] a The array.
76 /// \return The hash.
77 template <typename T, std::size_t N>
78 madness::hashT hash_value(const std::array<T,N>& a) {
79 // Use this version of range for potential optimization.
80 return madness::hash_range(a.data(), N);
81 }
82
83} // namespace madness
84
85#endif // MADNESS_WORLD_ARRAY_ADDONS_H__INCLUDED
Macros and tools pertaining to the configuration of MADNESS.
Defines madness::MadnessException for exception handling.
std::ostream & operator<<(std::ostream &s, const std::array< T, N > &a)
Output std::array to stream for human consumption.
Definition array_addons.h:59
Namespace for all elements and tools of MADNESS.
Definition DFParameters.h:10
void hash_range(hashT &seed, It first, It last)
Definition worldhash.h:280
std::size_t hashT
The hash value type.
Definition worldhash.h:145
madness::hashT hash_value(const std::array< T, N > &a)
Hash std::array with madness hash.
Definition array_addons.h:78
static const double a
Definition nonlinschro.cc:118
#define N
Definition testconv.cc:37
Defines hash functions for use in distributed containers.