Skip to content

Commit

Permalink
Member prefix ('m_') removed from all member variables (fixes #136).
Browse files Browse the repository at this point in the history
  • Loading branch information
offa committed Jun 5, 2018
1 parent 9ab26d3 commit b354a77
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 79 deletions.
22 changes: 11 additions & 11 deletions include/detail/scope_guard_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,17 @@ namespace sr::detail
>
explicit scope_guard_base(EFP&& exitFunction) noexcept(std::is_nothrow_constructible_v<EF, EFP>
|| std::is_nothrow_constructible_v<EF, EFP&>)
: m_exitfunction(std::forward<EFP>(exitFunction)),
m_execute_on_destruction(true)
: exitfunction(std::forward<EFP>(exitFunction)),
execute_on_destruction(true)
{
}

template<class EFP,
std::enable_if_t<std::is_constructible_v<EF, EFP>, int> = 0,
std::enable_if_t<std::is_lvalue_reference_v<EFP>, int> = 0
>
explicit scope_guard_base(EFP&& exitFunction) try : m_exitfunction(exitFunction),
m_execute_on_destruction(true)
explicit scope_guard_base(EFP&& exitFunction) try : exitfunction(exitFunction),
execute_on_destruction(true)
{
}
catch( ... )
Expand All @@ -95,8 +95,8 @@ namespace sr::detail
scope_guard_base(scope_guard_base&& other) noexcept(std::is_nothrow_move_constructible_v<EF>
|| std::is_nothrow_copy_constructible_v<EF>)
: Strategy(other),
m_exitfunction(forward_if_nothrow_move_constructible(other.m_exitfunction)),
m_execute_on_destruction(other.m_execute_on_destruction)
exitfunction(forward_if_nothrow_move_constructible(other.exitfunction)),
execute_on_destruction(other.execute_on_destruction)
{
other.release();
}
Expand All @@ -106,16 +106,16 @@ namespace sr::detail

~scope_guard_base() noexcept(is_noexcept_dtor_v<EF, Strategy>)
{
if( (m_execute_on_destruction == true) && (this->should_execute() == true) )
if( (execute_on_destruction == true) && (this->should_execute() == true) )
{
m_exitfunction();
exitfunction();
}
}


void release() noexcept
{
m_execute_on_destruction = false;
execute_on_destruction = false;
}


Expand All @@ -125,8 +125,8 @@ namespace sr::detail

private:

EF m_exitfunction;
bool m_execute_on_destruction;
EF exitfunction;
bool execute_on_destruction;
};

}
26 changes: 13 additions & 13 deletions include/detail/wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,35 +34,35 @@ namespace sr::detail
public:

template<class TT, class G, std::enable_if_t<std::is_constructible_v<T, TT>, int> = 0>
Wrapper(TT&& value, G&& g) noexcept(std::is_nothrow_constructible_v<T, TT>) : m_value(std::forward<TT>(value))
Wrapper(TT&& v, G&& g) noexcept(std::is_nothrow_constructible_v<T, TT>) : value(std::forward<TT>(v))
{
g.release();
}


T& get() noexcept
{
return m_value;
return value;
}

const T& get() const noexcept
{
return m_value;
return value;
}

void reset(Wrapper<T>&& other) noexcept
{
m_value = std::move(other.m_value);
value = std::move(other.value);
}

void reset(T&& newValue) noexcept(std::is_nothrow_assignable_v<T, decltype(std::move_if_noexcept(newValue))>)
{
m_value = std::forward<T>(newValue);
value = std::forward<T>(newValue);
}

void reset(const T& newValue) noexcept(std::is_nothrow_assignable_v<T, const T&>)
{
m_value = newValue;
value = newValue;
}


Expand All @@ -71,7 +71,7 @@ namespace sr::detail

private:

T m_value;
T value;
};


Expand All @@ -81,30 +81,30 @@ namespace sr::detail
public:

template<class TT, class G, std::enable_if_t<std::is_convertible_v<TT, T&>, int> = 0>
Wrapper(TT&& value, G&& g) noexcept(std::is_nothrow_constructible_v<TT, T&>) : m_value(static_cast<T&>(value))
Wrapper(TT&& v, G&& g) noexcept(std::is_nothrow_constructible_v<TT, T&>) : value(static_cast<T&>(v))
{
g.release();
}


T& get() noexcept
{
return m_value.get();
return value.get();
}

const T& get() const noexcept
{
return m_value.get();
return value.get();
}

void reset(Wrapper<T>&& other) noexcept
{
m_value = std::move(other.m_value);
value = std::move(other.value);
}

void reset(T& newValue) noexcept
{
m_value = std::ref(newValue);
value = std::ref(newValue);
}


Expand All @@ -113,7 +113,7 @@ namespace sr::detail

private:

type m_value;
type value;
};

}
4 changes: 2 additions & 2 deletions include/scope_fail.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ namespace sr
{
bool should_execute() const noexcept
{
return std::uncaught_exceptions() > m_uncaught_on_creation;
return std::uncaught_exceptions() > uncaught_on_creation;
}


int m_uncaught_on_creation = std::uncaught_exceptions();
int uncaught_on_creation = std::uncaught_exceptions();
};

}
Expand Down
4 changes: 2 additions & 2 deletions include/scope_success.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ namespace sr
{
bool should_execute() const noexcept
{
return std::uncaught_exceptions() <= m_uncaught_on_creation;
return std::uncaught_exceptions() <= uncaught_on_creation;
}


int m_uncaught_on_creation = std::uncaught_exceptions();
int uncaught_on_creation = std::uncaught_exceptions();
};


Expand Down
58 changes: 29 additions & 29 deletions include/unique_resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,19 @@ namespace sr
>
explicit unique_resource(RR&& r, DD&& d) noexcept((std::is_nothrow_constructible_v<R, RR> || std::is_nothrow_constructible_v<R, RR&>)
&& (std::is_nothrow_constructible_v<D, DD> || std::is_nothrow_constructible_v<D, DD&>))
: m_resource(detail::forward_if_nothrow_constructible<R, RR>(std::forward<RR>(r)), scope_exit{[&r, &d] { d(r); }}),
m_deleter(detail::forward_if_nothrow_constructible<D, DD>(std::forward<DD>(d)), scope_exit{[this, &d] { d(get()); }}),
m_execute_on_destruction(true)
: resource(detail::forward_if_nothrow_constructible<R, RR>(std::forward<RR>(r)), scope_exit{[&r, &d] { d(r); }}),
deleter(detail::forward_if_nothrow_constructible<D, DD>(std::forward<DD>(d)), scope_exit{[this, &d] { d(get()); }}),
execute_on_destruction(true)
{
}

unique_resource(unique_resource&& other) noexcept(std::is_nothrow_move_constructible_v<R>
&& std::is_nothrow_move_constructible_v<D>)
: m_resource(std::move_if_noexcept(other.m_resource.get()), scope_exit{[] { }}),
m_deleter(std::move_if_noexcept(other.m_deleter.get()), scope_exit{[&other] {
other.get_deleter()(other.m_resource.get());
: resource(std::move_if_noexcept(other.resource.get()), scope_exit{[] { }}),
deleter(std::move_if_noexcept(other.deleter.get()), scope_exit{[&other] {
other.get_deleter()(other.resource.get());
other.release(); }}),
m_execute_on_destruction(std::exchange(other.m_execute_on_destruction, false))
execute_on_destruction(std::exchange(other.execute_on_destruction, false))
{
}

Expand All @@ -79,10 +79,10 @@ namespace sr

void reset() noexcept
{
if( m_execute_on_destruction == true )
if( execute_on_destruction == true )
{
m_execute_on_destruction = false;
get_deleter()(m_resource.get());
execute_on_destruction = false;
get_deleter()(resource.get());
}
}

Expand All @@ -96,31 +96,31 @@ namespace sr

if constexpr( std::is_nothrow_assignable_v<R1&, RR> == true )
{
m_resource.reset(std::forward<RR>(r));
resource.reset(std::forward<RR>(r));
}
else
{
m_resource.reset(std::as_const(r));
resource.reset(std::as_const(r));
}

m_execute_on_destruction = true;
execute_on_destruction = true;
se.release();
}

void release() noexcept
{
m_execute_on_destruction = false;
execute_on_destruction = false;
}

const R& get() const noexcept
{
return m_resource.get();
return resource.get();
}

template<class RR = R, std::enable_if_t<std::is_pointer_v<RR>, int> = 0>
RR operator->() const noexcept
{
return m_resource.get();
return resource.get();
}

template<class RR = R,
Expand All @@ -133,7 +133,7 @@ namespace sr

const D& get_deleter() const noexcept
{
return m_deleter.get();
return deleter.get();
}


Expand All @@ -154,30 +154,30 @@ namespace sr
{
if constexpr( std::is_nothrow_move_assignable_v<DD> == true )
{
m_resource.reset(std::move(other.m_resource));
m_deleter.reset(std::move(other.m_deleter));
resource.reset(std::move(other.resource));
deleter.reset(std::move(other.deleter));
}
else
{
m_deleter.reset(other.m_deleter);
m_resource.reset(std::move(other.m_resource));
deleter.reset(other.deleter);
resource.reset(std::move(other.resource));
}
}
else
{
if constexpr( std::is_nothrow_move_assignable_v<DD> == true )
{
m_resource.reset(other.m_resource);
m_deleter.reset(std::move(other.m_deleter));
resource.reset(other.resource);
deleter.reset(std::move(other.deleter));
}
else
{
m_resource.reset(other.m_resource);
m_deleter.reset(other.m_deleter);
resource.reset(other.resource);
deleter.reset(other.deleter);
}
}

m_execute_on_destruction = std::exchange(other.m_execute_on_destruction, false);
execute_on_destruction = std::exchange(other.execute_on_destruction, false);
}
return *this;
}
Expand All @@ -187,9 +187,9 @@ namespace sr

private:

detail::Wrapper<R> m_resource;
detail::Wrapper<D> m_deleter;
bool m_execute_on_destruction;
detail::Wrapper<R> resource;
detail::Wrapper<D> deleter;
bool execute_on_destruction;
};


Expand Down
Loading

0 comments on commit b354a77

Please sign in to comment.