Compare commits

..
Author SHA1 Message Date
Dmitry Kobets 4c6f7b2923 Mark dynamic_extent as inline, compiler-version-permitting 2022-07-01 10:23:21 -07:00
Dmitry Kobets be0a8a2caa Test solution 2022-07-01 10:23:11 -07:00
4 changed files with 30 additions and 31 deletions
+1 -1
View File
@@ -29,7 +29,7 @@ jobs:
echo "Emulator starting"
- name: Configure
run: cmake -Werror=dev -DCMAKE_TOOLCHAIN_FILE=$ANDROID_HOME/ndk/25.0.8775105/build/cmake/android.toolchain.cmake -DANDROID_PLATFORM=16 -DANDROID_ABI=x86_64 -DCMAKE_BUILD_TYPE=Debug ..
run: cmake -Werror=dev -DCMAKE_TOOLCHAIN_FILE=$ANDROID_HOME/ndk-bundle/build/cmake/android.toolchain.cmake -DANDROID_PLATFORM=16 -DANDROID_ABI=x86_64 -DCMAKE_BUILD_TYPE=Debug ..
- name: Build
run: cmake --build . --parallel
+6 -8
View File
@@ -343,18 +343,16 @@ namespace details
};
}} // namespace gsl::details
namespace std
{
template <class Type>
struct pointer_traits<::gsl::details::span_iterator<Type>>
{
using pointer = ::gsl::details::span_iterator<Type>;
using element_type = Type;
struct std::pointer_traits<::gsl::details::span_iterator<Type>> {
using pointer = ::gsl::details::span_iterator<Type>;
using element_type = Type;
using difference_type = ptrdiff_t;
static constexpr element_type* to_address(const pointer i) noexcept { return i.current_; }
static constexpr element_type* to_address(const pointer i) noexcept {
return i.current_;
}
};
} // namespace std
namespace gsl { namespace details {
template <std::size_t Ext>
+23 -12
View File
@@ -65,29 +65,40 @@ template <class F>
class final_action
{
public:
explicit final_action(const F& ff) noexcept : f{ff} { }
explicit final_action(F&& ff) noexcept : f{std::move(ff)} { }
static_assert(!std::is_reference<F>::value && !std::is_const<F>::value &&
!std::is_volatile<F>::value,
"Final_action should store its callable by value");
~final_action() noexcept { if (invoke) f(); }
explicit final_action(F f) noexcept : f_(std::move(f)) {}
final_action(final_action&& other) noexcept
: f(std::move(other.f)), invoke(std::exchange(other.invoke, false))
{ }
: f_(std::move(other.f_)), invoke_(std::exchange(other.invoke_, false))
{}
final_action(const final_action&) = delete;
void operator=(const final_action&) = delete;
void operator=(final_action&&) = delete;
final_action(const final_action&) = delete;
final_action& operator=(const final_action&) = delete;
final_action& operator=(final_action&&) = delete;
// clang-format off
GSL_SUPPRESS(f.6) // NO-FORMAT: attribute // terminate if throws
// clang-format on
~final_action() noexcept
{
if (invoke_) f_();
}
private:
F f;
bool invoke = true;
F f_;
bool invoke_{true};
};
// finally() - convenience function to generate a final_action
template <class F>
GSL_NODISCARD auto finally(F&& f) noexcept
GSL_NODISCARD final_action<typename std::remove_cv<typename std::remove_reference<F>::type>::type>
finally(F&& f) noexcept
{
return final_action<std::decay_t<F>>{std::forward<F>(f)};
return final_action<typename std::remove_cv<typename std::remove_reference<F>::type>::type>(
std::forward<F>(f));
}
// narrow_cast(): a searchable way to do narrowing casts of values
-10
View File
@@ -112,16 +112,6 @@ TEST(utils_tests, finally_function_ptr)
EXPECT_TRUE(j == 1);
}
TEST(utils_tests, finally_function)
{
j = 0;
{
auto _ = finally(g);
EXPECT_TRUE(j == 0);
}
EXPECT_TRUE(j == 1);
}
TEST(utils_tests, narrow_cast)
{
int n = 120;