Galois
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
OperatorReferenceTypes.h
Go to the documentation of this file.
1 /*
2  * This file belongs to the Galois project, a C++ library for exploiting
3  * parallelism. The code is being released under the terms of the 3-Clause BSD
4  * License (a copy is located in LICENSE.txt at the top-level directory).
5  *
6  * Copyright (C) 2018, The University of Texas at Austin. All rights reserved.
7  * UNIVERSITY EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES CONCERNING THIS
8  * SOFTWARE AND DOCUMENTATION, INCLUDING ANY WARRANTIES OF MERCHANTABILITY,
9  * FITNESS FOR ANY PARTICULAR PURPOSE, NON-INFRINGEMENT AND WARRANTIES OF
10  * PERFORMANCE, AND ANY WARRANTY THAT MIGHT OTHERWISE ARISE FROM COURSE OF
11  * DEALING OR USAGE OF TRADE. NO WARRANTY IS EITHER EXPRESS OR IMPLIED WITH
12  * RESPECT TO THE USE OF THE SOFTWARE OR DOCUMENTATION. Under no circumstances
13  * shall University be liable for incidental, special, indirect, direct or
14  * consequential damages or loss of profits, interruption of business, or
15  * related expenses which may arise from use of Software or Documentation,
16  * including but not limited to those resulting from defects in Software and/or
17  * Documentation, or loss or inaccuracy of data of any kind.
18  */
19 
20 #ifndef GALOIS_RUNTIME_OPERATOR_REFERENCE_TYPES_H
21 #define GALOIS_RUNTIME_OPERATOR_REFERENCE_TYPES_H
22 
23 #include "galois/config.h"
24 
25 namespace galois {
26 namespace runtime {
27 
28 namespace internal {
29 
30 // Helper template for getting the appropriate type of
31 // reference to hold within each executor based off of the
32 // type of reference that was passed to it.
33 
34 // Don't accept operators by value.
35 template <typename FuncTy>
36 struct OperatorReferenceType_impl;
37 
38 // Const references are propagated.
39 // If a user supplies a const reference the operator() on the
40 // given object must be callable with *this passed as const as well.
41 template <typename FuncNoRef>
42 struct OperatorReferenceType_impl<FuncNoRef const&> {
43  using type = FuncNoRef const&;
44 };
45 
46 // Non-const references continue to be non-const.
47 template <typename FuncNoRef>
48 struct OperatorReferenceType_impl<FuncNoRef&> {
49  using type = FuncNoRef&;
50 };
51 
52 // Inside each executor store a reference to a received rvalue reference
53 // and then use that to pass to the various threads. This must be done in
54 // a way that keeps the rvalue reference alive throughout the duration of
55 // the parallel loop (as long as the resulting lvalue reference is used
56 // anywhere).
57 template <typename FuncNoRef>
58 struct OperatorReferenceType_impl<FuncNoRef&&> {
59  using type = FuncNoRef&;
60 };
61 
62 } // namespace internal
63 
64 template <typename T>
66  typename internal::OperatorReferenceType_impl<T>::type;
67 
68 } // namespace runtime
69 } // namespace galois
70 
71 #endif // ifndef(GALOIS_RUNTIME_OPERATOR_REFERENCE_TYPES_H)
typename internal::OperatorReferenceType_impl< T >::type OperatorReferenceType
Definition: OperatorReferenceTypes.h:66