thor-os/tstl/include/pair.hpp
Baptiste Wicht e3c66b0faa Cleanup
2016-09-25 21:04:42 +02:00

74 lines
1.8 KiB
C++

//=======================================================================
// Copyright Baptiste Wicht 2013-2016.
// Distributed under the terms of the MIT License.
// (See accompanying file LICENSE or copy at
// http://www.opensource.org/licenses/MIT)
//=======================================================================
#ifndef PAIR_H
#define PAIR_H
namespace std {
template<typename T1, typename T2>
class pair {
public:
using first_type = T1;
using second_type = T2;
first_type first;
second_type second;
//Constructor
constexpr pair(const first_type& a, const second_type& b) : first(a), second(b){
//Nothing to init
}
template<typename U1, typename U2>
constexpr pair(U1&& x, U2&& y) : first(std::forward<U1>(x)), second(std::forward<U2>(y)){
//Nothing to init
}
//Copy constructors
constexpr pair(const pair&) = default;
template<typename U1, typename U2>
constexpr pair(const pair<U1, U2>& p) : first(p.first), second(p.second) {
//Nothing to init
}
template<typename U1, typename U2>
pair& operator=(const pair<U1, U2>& p){
first = p.first;
second = p.second;
return *this;
}
//Move constructors
constexpr pair(pair&&) = default;
template<typename U1, typename U2>
constexpr pair(pair<U1, U2>&& p) : first(std::move(p.first)), second(std::move(p.second)) {
//Nothing to init
}
template<typename U1, typename U2>
pair& operator=(pair<U1, U2>&& p){
first = std::forward<U1>(p.first);
second = std::forward<U2>(p.second);
return *this;
}
};
template<typename T1, typename T2>
inline constexpr pair<T1, T2> make_pair(T1&& x, T2&& y){
return pair<T1, T2>(std::forward<T1>(x), std::forward<T2>(y));
}
} //end of namespace std
#endif