-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
propagate_const: Implemented the arrow operator.
- Loading branch information
Showing
2 changed files
with
96 additions
and
18 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,43 @@ | ||
#pragma once | ||
|
||
#include <utility> | ||
#include <type_traits> | ||
#include <memory> | ||
|
||
template <typename T> | ||
class propagate_const final | ||
namespace sw | ||
{ | ||
T t_; | ||
public: | ||
using element_type = int; | ||
template <typename T> | ||
class propagate_const final | ||
{ | ||
T t_; | ||
public: | ||
using element_type = typename std::pointer_traits<T>::element_type; | ||
|
||
constexpr propagate_const() = default; | ||
constexpr propagate_const( propagate_const&& p ) = default; | ||
propagate_const( const propagate_const& ) = delete; | ||
constexpr propagate_const() = default; | ||
constexpr propagate_const(propagate_const&&) = default; | ||
template <class U> | ||
constexpr explicit(!std::is_convertible<U, T>::value) propagate_const(U &&u) : | ||
t_{std::forward<U>(u)} | ||
{} | ||
propagate_const(const propagate_const&) = delete; | ||
|
||
constexpr propagate_const& operator=(propagate_const&&) = default; | ||
template< class U > | ||
constexpr propagate_const& operator=(U&& u) | ||
{ | ||
t_ = std::forward<U>(u); | ||
} | ||
propagate_const& operator=( const propagate_const& ) = delete; | ||
}; | ||
constexpr propagate_const& operator=(propagate_const&&) = default; | ||
template <class U> | ||
constexpr propagate_const& operator=(U&& u) | ||
{ | ||
t_ = std::forward<U>(u); | ||
return *this; | ||
} | ||
propagate_const& operator=(const propagate_const&) = delete; | ||
|
||
constexpr element_type* operator->() | ||
{ | ||
return std::to_address(t_); | ||
} | ||
|
||
constexpr element_type const* operator->() const | ||
{ | ||
return std::to_address(t_); | ||
} | ||
}; | ||
} |
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