-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enforce element types of DASH containers to be trivially copyable #293
Merged
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
95318b3
Containers: require type to be trivially_copyable
devreal 6315b26
Check for minimum compiler versions known to support required features
devreal 703dbb8
Merge branch 'bug-241-containertypes' of github.com:dash-project/dash…
devreal 8fb5e9d
Make GlobPtr trivially copyable
devreal 07b6576
Introduce dash::Pair, which is trivially copyable (as opposed to std:…
devreal 2d21903
dash::Pair: Initialize members in default constructor
devreal 1cd74cf
Merge branch 'development' into bug-241-containertypes
fuchsto a86a7bc
Merge branch 'development' into bug-241-containertypes
fuchsto File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,210 @@ | ||
#ifndef DASH_DASH_INCLUDE_DASH_PAIR_H_ | ||
#define DASH_DASH_INCLUDE_DASH_PAIR_H_ | ||
|
||
#include <type_traits> | ||
|
||
namespace dash { | ||
|
||
/** | ||
* A trivially-copyable implementation of std::pair to be used | ||
* as element type of DASH containers. | ||
* | ||
* The implementation was mainly taken and adapted from std_pair.h. | ||
* | ||
* \todo Implementation of tuples are missing at the moment. | ||
*/ | ||
template<class T1, class T2> | ||
struct Pair | ||
{ | ||
typedef T1 first_type; /// @c first_type is the first bound type | ||
typedef T2 second_type; /// @c second_type is the second bound type | ||
|
||
T1 first; /// @c first is a copy of the first object | ||
T2 second; /// @c second is a copy of the second object | ||
|
||
/** | ||
* The default constructor. | ||
*/ | ||
constexpr Pair() | ||
: first(), second() | ||
{ } | ||
|
||
/** | ||
* Two objects may be passed to a Pair constructor to be copied. | ||
*/ | ||
constexpr Pair(const T1& __a, const T2& __b) | ||
: first(__a), second(__b) | ||
{ } | ||
|
||
/** | ||
* A Pair might be constructed from another pair iff first and second | ||
* are convertible. | ||
*/ | ||
template<class U1, class U2, class = typename | ||
std::enable_if< | ||
std::is_convertible<const U1&, T1>::value && | ||
std::is_convertible<const U2&, T2>::value>::value> | ||
constexpr Pair(const Pair<U1, U2>& p) | ||
: first(p.first), second(p.second) | ||
{ } | ||
|
||
constexpr Pair(const Pair&) = default; | ||
constexpr Pair(Pair&&) = default; | ||
|
||
template<class U1, class = typename | ||
std::enable_if<std::is_convertible<U1, T1>::value>::type> | ||
constexpr Pair(U1&& x, const T2& y) | ||
: first(std::forward<U1>(x)), second(y) | ||
{ } | ||
|
||
template<class U2, class = typename | ||
std::enable_if<std::is_convertible<U2, T2>::value>::type> | ||
constexpr Pair(const T1& x, U2&& y) | ||
: first(x), second(std::forward<U2>(y)) | ||
{ } | ||
|
||
template<class U1, class U2, class = typename | ||
std::enable_if<std::is_convertible<U1, T1>::value && | ||
std::is_convertible<U2, T2>::value>::type> | ||
constexpr Pair(U1&& x, U2&& y) | ||
: first(std::forward<U1>(x)), second(std::forward<U2>(y)) | ||
{ } | ||
|
||
template<class U1, class U2, class = typename | ||
std::enable_if<std::is_convertible<U1, T1>::value && | ||
std::is_convertible<U2, T2>::value>::type> | ||
constexpr Pair(Pair<U1, U2>&& p) | ||
: first(std::forward<U1>(p.first)), | ||
second(std::forward<U2>(p.second)) | ||
{ } | ||
|
||
Pair& | ||
operator=(const Pair& p) = default; | ||
|
||
Pair& | ||
operator=(Pair&& p) | ||
noexcept( | ||
std::is_nothrow_move_assignable<T1>::value && | ||
std::is_nothrow_move_assignable<T2>::value) = default; | ||
|
||
template<class U1, class U2> | ||
Pair& | ||
operator=(const Pair<U1, U2>& p) | ||
{ | ||
first = p.first; | ||
second = p.second; | ||
return *this; | ||
} | ||
|
||
template<class U1, class U2> | ||
Pair& | ||
operator=(Pair<U1, U2>&& p) | ||
{ | ||
first = std::forward<U1>(p.first); | ||
second = std::forward<U2>(p.second); | ||
return *this; | ||
} | ||
|
||
void | ||
swap(Pair& p) | ||
noexcept(noexcept(swap(first, p.first)) | ||
&& noexcept(swap(second, p.second))) | ||
{ | ||
std::swap(first, p.first); | ||
std::swap(second, p.second); | ||
} | ||
}; | ||
|
||
/** | ||
* Two pairs of the same type are equal iff their members are equal. | ||
*/ | ||
template<class T1, class T2> | ||
inline constexpr bool | ||
operator==(const Pair<T1, T2>& x, const Pair<T1, T2>& y) | ||
{ | ||
return x.first == y.first && x.second == y.second; | ||
} | ||
|
||
/** | ||
* A pair is smaller than another pair if the first member is smaller | ||
* or the first is equal and the second is smaller. | ||
* See <http://gcc.gnu.org/onlinedocs/libstdc++/manual/utilities.html> | ||
*/ | ||
template<class T1, class T2> | ||
inline constexpr bool | ||
operator<(const Pair<T1, T2>& x, const Pair<T1, T2>& y) | ||
{ | ||
return x.first < y.first | ||
|| (!(y.first < x.first) && !(x.second >= y.second)); | ||
} | ||
|
||
/** | ||
* Inequality comparison operator implemented in terms of | ||
* equality operator. | ||
*/ | ||
template<class T1, class T2> | ||
inline constexpr bool | ||
operator!=(const Pair<T1, T2>& x, const Pair<T1, T2>& y) | ||
{ | ||
return !(x == y); | ||
} | ||
|
||
/** | ||
* Greater-than operator implemented in terms of less-than operator. | ||
*/ | ||
template<class T1, class T2> | ||
inline constexpr bool | ||
operator>(const Pair<T1, T2>& x, const Pair<T1, T2>& y) | ||
{ | ||
return y < x; | ||
} | ||
|
||
/** | ||
* Less-than-or-equal operator implemented in terms of less-than operator. | ||
*/ | ||
template<class T1, class T2> | ||
inline constexpr bool | ||
operator<=(const Pair<T1, T2>& x, const Pair<T1, T2>& y) | ||
{ | ||
return !(y < x); | ||
} | ||
|
||
/** | ||
* Greater-than-or-equal operator implemented in terms of less-than operator. | ||
*/ | ||
template<class T1, class T2> | ||
inline constexpr bool | ||
operator>=(const Pair<T1, T2>& x, const Pair<T1, T2>& y) | ||
{ | ||
return !(x < y); | ||
} | ||
|
||
/** | ||
* Wrapper for Pair::swap. | ||
*/ | ||
template<class T1, class T2> | ||
inline void | ||
swap(Pair<T1, T2>& x, Pair<T1, T2>& y) | ||
noexcept(noexcept(x.swap(y))) | ||
{ | ||
x.swap(y); | ||
} | ||
|
||
/** | ||
* Convennience wrapper to create a Pair object. | ||
*/ | ||
template<class T1, class T2> | ||
constexpr Pair<typename std::__decay_and_strip<T1>::__type, | ||
typename std::__decay_and_strip<T2>::__type> | ||
make_pair(T1&& x, T2&& y) | ||
{ | ||
typedef typename std::__decay_and_strip<T1>::__type ds_type1; | ||
typedef typename std::__decay_and_strip<T2>::__type ds_type2; | ||
typedef Pair<ds_type1, ds_type2> pair_type; | ||
return pair_type(std::forward<T1>(x), std::forward<T2>(y)); | ||
} | ||
|
||
} // namespace dash | ||
|
||
|
||
#endif /* DASH_DASH_INCLUDE_DASH_PAIR_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Intel compilers (tested 16.0 and 17.0) don't allow
std::is_trivially_copyable
either. Why did you remove this check?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because they do. I just tested with Intel 17.0 and I am sure I also verified 16 back when we discussed #241. Keep in mind that the Intel compiler relies on the GNU-provided STL so you might have to load a newer GCC module (at least I have to do that on our Linux cluster).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that seems alright.
I actually did test exactly that, but it's apparently specific to our dev server. When reloading gcc after loading the icc module, there is some hickup and the newer version of gcc is not used.