Skip to content

Commit

Permalink
re-done mini::pair
Browse files Browse the repository at this point in the history
  • Loading branch information
wbenny committed Dec 26, 2018
1 parent 8b05bb4 commit d5c8f61
Showing 1 changed file with 188 additions and 19 deletions.
207 changes: 188 additions & 19 deletions mini/pair.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,23 @@ struct pair
using first_type = TFirst;
using second_type = TSecond;

pair(
//
// constructors.
//

constexpr pair(
void
) = default;

pair(
constexpr pair(
const pair& other
) = default;

constexpr pair(
pair&& other
) = default;

constexpr pair(
const TFirst& first,
const TSecond& second
)
Expand All @@ -26,11 +38,35 @@ struct pair

}

constexpr pair(
TFirst&& first,
TSecond&& second
)
: first(std::forward<TFirst>(first))
, second(std::forward<TSecond>(second))
{

}

template <
typename TOtherFirst,
typename TOtherSecond
>
pair(
constexpr pair(
const TOtherFirst& first,
const TOtherSecond& second
)
: first(first)
, second(second)
{

}

template <
typename TOtherFirst,
typename TOtherSecond
>
constexpr pair(
TOtherFirst&& first,
TOtherSecond&& second
)
Expand All @@ -40,48 +76,181 @@ struct pair

}

pair(
const pair<TFirst, TSecond>& other
) = default;
template <
typename TOtherFirst,
typename TOtherSecond
>
constexpr pair(
const pair<TOtherFirst, TOtherSecond>& other
)
: first(other.first)
, second(other.second)
{

pair(
pair<TFirst, TSecond>&& other
}

template <
typename TOtherFirst,
typename TOtherSecond
>
constexpr pair(
pair<TOtherFirst, TOtherSecond>&& other
)
: first(std::forward<TOtherFirst>(other.first))
, second(std::forward<TOtherSecond>(other.second))
{
swap(other);

}

//
// destructor.
//

~pair(
void
) = default;

pair<TFirst, TSecond>&
//
// assign operators.
//

constexpr pair&
operator=(
const pair& other
) = default;

constexpr pair&
operator=(
const pair<TFirst, TSecond>& other
pair&& other
) = default;

pair<TFirst, TSecond>&
template <
typename TOtherFirst,
typename TOtherSecond
>
constexpr pair&
operator=(
pair<TFirst, TSecond>&& other
const pair<TOtherFirst, TOtherSecond>& other
)
{
swap(other);
return *this;
first = other.first;
second = other.second;
}

void
template <
typename TOtherFirst,
typename TOtherSecond
>
constexpr pair&
operator=(
pair<TOtherFirst, TOtherSecond>&& other
)
{
first = std::forward<TOtherFirst>(other.first);
second = std::forward<TOtherSecond>(other.second);
}

//
// swap.
//

constexpr void
swap(
pair<TFirst, TSecond>& other
pair& other
)
{
mini::swap(first, other.first);
mini::swap(second, other.second);
}

TFirst first;
TSecond second;
first_type first;
second_type second;
};

//
// non-member operations.
//

template<
typename TFirst,
typename TSecond
>
constexpr bool
operator==(
const pair<TFirst, TSecond>& lhs,
const pair<TFirst, TSecond>& rhs
)
{
return lhs.first == rhs.first && lhs.second == rhs.second;
}

template<
typename TFirst,
typename TSecond
>
constexpr bool
operator!=(
const pair<TFirst, TSecond>& lhs,
const pair<TFirst, TSecond>& rhs
)
{
return !(lhs == rhs);
}

template<
typename TFirst,
typename TSecond
>
constexpr bool
operator<(
const pair<TFirst, TSecond>& lhs,
const pair<TFirst, TSecond>& rhs
)
{
return (lhs.first < rhs.first ||
(!(rhs.first < lhs.first) &&
lhs.second < rhs.second));
}

template<
typename TFirst,
typename TSecond
>
constexpr bool
operator<=(
const pair<TFirst, TSecond>& lhs,
const pair<TFirst, TSecond>& rhs
)
{
return !(rhs < lhs);
}

template<
typename TFirst,
typename TSecond
>
constexpr bool
operator>(
const pair<TFirst, TSecond>& lhs,
const pair<TFirst, TSecond>& rhs
)
{
return rhs < lhs;
}

template<
typename TFirst,
typename TSecond
>
constexpr bool
operator>=(
const pair<TFirst, TSecond>& lhs,
const pair<TFirst, TSecond>& rhs
)
{
return !(lhs < rhs);
}

template <
typename TFirst,
typename TSecond
Expand Down

0 comments on commit d5c8f61

Please sign in to comment.