Skip to content

Commit

Permalink
latest from coda-oss
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Smith committed Feb 4, 2022
1 parent 409adfa commit e93b9e5
Show file tree
Hide file tree
Showing 18 changed files with 180 additions and 166 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
namespace coda_oss
{
#if defined(GSL_BYTE_H) // the above #include'd gsl/byte
using byte = gsl::byte;
using gsl::byte;
#else // no gsl::byte, use our own
// https://en.cppreference.com/w/cpp/types/byte
enum class byte : unsigned char {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,13 @@
#define CODA_OSS_coda_oss_optional_h_INCLUDED_
#pragma once

#include <assert.h>

#include <utility>
#include <stdexcept>

#include "coda_oss/namespace_.h"
#include "coda_oss/optional_.h"

namespace coda_oss
{
template<typename T>
using optional = details::optional<T>;

// https://en.cppreference.com/w/cpp/utility/optional/make_optional
template <typename T, typename... TArgs>
inline optional<T> make_optional(TArgs&&... args)
{
return details::make_optional<T>(std::forward<TArgs>(args)...);
using details::optional;
using details::make_optional;
}
}

#define CODA_OSS_coda_oss_optional 201606L // c.f., __cpp_lib_optional

#endif // CODA_OSS_coda_oss_optional_h_INCLUDED_
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
#define CODA_OSS_coda_oss_span_h_INCLUDED_
#pragma once

#include <assert.h>
#include <stddef.h>

#include "coda_oss/namespace_.h"
#include "coda_oss/span_.h"

Expand All @@ -36,11 +33,9 @@
namespace coda_oss
{
#if defined(GSL_SPAN_H) // the above #include'd gsl/span
template <typename T>
using span = gsl::span<T>;
using gsl::span;
#else // no gsl::span, use our own
template <typename T>
using span = details::span<T>;
using details::span;
#endif // GSL_SPAN_H
}

Expand Down
22 changes: 13 additions & 9 deletions externals/coda-oss/modules/c++/coda_oss/include/coda_oss/span_.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,6 @@ struct span final
}
span(const span&) noexcept = default;

template <typename TContainer>
span(TContainer& c) : span(c.data(), c.size())
{
}
template <typename TContainer>
span(const TContainer& c) : span(const_cast<TContainer&>(c))
{
}

// https://en.cppreference.com/w/cpp/container/span/data
constexpr pointer data() const noexcept
{
Expand Down Expand Up @@ -87,6 +78,19 @@ struct span final
return size() == 0;
}

using iterator = pointer;
// https://en.cppreference.com/w/cpp/container/span/begin
constexpr iterator begin() const noexcept
{
return data();
}

// https://en.cppreference.com/w/cpp/container/span/end
constexpr iterator end() const noexcept
{
return begin() + size();
}

private:
pointer p_ = nullptr;
size_type sz_ = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,16 @@
namespace coda_oss
{
// workaround missing "is_trivially_copyable" in g++ < 5.0
// https://stackoverflow.com/a/31798726/8877
#if defined(__GNUC__) && (__GNUC__ < 5)
template <typename T>
struct is_trivially_copyable final
{
static_assert(CODA_OSS_cplusplus < 201402L, "C++14 must have is_trivially_copyable.");
// https://stackoverflow.com/a/31798726/8877
static constexpr bool value = __has_trivial_copy(T);
};
#else
template <typename T>
using is_trivially_copyable = std::is_trivially_copyable<T>;
using std::is_trivially_copyable;
#endif
}

Expand Down
8 changes: 8 additions & 0 deletions externals/coda-oss/modules/c++/mem/unittests/test_Span.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ namespace
TEST_ASSERT_EQ(ints.size(), span.size());
TEST_ASSERT_EQ(ints.data(), span.data());

const size_t dist = std::distance(span.begin(), span.end());
TEST_ASSERT_EQ(span.size(), dist);

TEST_ASSERT_EQ(1, span[0]);
TEST_ASSERT_EQ(1, *(span.begin()));
TEST_ASSERT_EQ(5, span[4]);

span[0] = span[4];
Expand All @@ -63,7 +67,11 @@ static void testSpanVector_(const std::string& testName,
TEST_ASSERT_EQ(ints.size(), span.size());
TEST_ASSERT_EQ(ints.data(), span.data());

const size_t dist = std::distance(span.begin(), span.end());
TEST_ASSERT_EQ(span.size(), dist);

TEST_ASSERT_EQ(1, span[0]);
TEST_ASSERT_EQ(1, *(span.begin()));
TEST_ASSERT_EQ(5, span[4]);
}
TEST_CASE(testSpanVector)
Expand Down
33 changes: 16 additions & 17 deletions externals/coda-oss/modules/c++/std/include/std/bit
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* =========================================================================
* This file is part of sys-c++
* This file is part of std-c++
* =========================================================================
*
* (C) Copyright 2021, Maxar Technologies, Inc.
*
* sys-c++ is free software; you can redistribute it and/or modify
* std-c++ is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
Expand All @@ -23,28 +23,27 @@
#pragma once

// Make it (too?) easy for clients to get our various std:: implementations

#include "coda_oss/bit.h"

#include "coda_oss/CPlusPlus.h"
#if CODA_OSS_cpp17
// Some C++17 implementations have <bit>
#if __has_include(<bit>) // __has_include is C++17
#include <bit>
#undef CODA_OSS_NO_std_endian
#define CODA_OSS_NO_std_endian 1 // don't need our own
#endif
#endif

#ifndef CODA_OSS_NO_std_endian
#define CODA_OSS_NO_std_endian 0 // enabled, unless explicitly disabled

#include "coda_oss/CPlusPlus.h"
#if CODA_OSS_cpp17
// Some C++17 implementations have <bit>
#if __has_include(<bit>) // __has_include is C++17
#include <bit>
#undef CODA_OSS_NO_std_endian
#define CODA_OSS_NO_std_endian 1 // don't need our own
#endif
#endif
#endif

#if !CODA_OSS_NO_std_endian
namespace std // This is slightly uncouth: we're not supposed to augment "std".
{
using endian = coda_oss::endian;
}
namespace std // This is slightly uncouth: we're not supposed to augment "std".
{
using coda_oss::endian;
}
#endif // CODA_OSS_NO_std_endian

#endif // CODA_OSS_std_bit_INCLUDED_
22 changes: 11 additions & 11 deletions externals/coda-oss/modules/c++/std/include/std/cstddef
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* =========================================================================
* This file is part of sys-c++
* This file is part of std-c++
* =========================================================================
*
* (C) Copyright 2021, Maxar Technologies, Inc.
*
* sys-c++ is free software; you can redistribute it and/or modify
* std-c++ is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
Expand All @@ -25,22 +25,22 @@
#include <cstddef>

// Make it (too?) easy for clients to get our various std:: implementations

#include "coda_oss/cstddef.h"
#if defined(__cpp_lib_byte) && (__cpp_lib_byte >= 201603L) // https://en.cppreference.com/w/cpp/utility/feature_test
#undef CODA_OSS_NO_std_byte
#define CODA_OSS_NO_std_byte 1 // don't need our own
#endif

#ifndef CODA_OSS_NO_std_byte
#define CODA_OSS_NO_std_byte 0 // enabled, unless explicitly disabled

#if defined(__cpp_lib_byte) && (__cpp_lib_byte >= 201603L) // https://en.cppreference.com/w/cpp/utility/feature_test
#undef CODA_OSS_NO_std_byte
#define CODA_OSS_NO_std_byte 1 // don't need our own
#endif
#endif

#if !CODA_OSS_NO_std_byte
namespace std // This is slightly uncouth: we're not supposed to augment "std".
{
using byte = coda_oss::byte;
}
namespace std // This is slightly uncouth: we're not supposed to augment "std".
{
using coda_oss::byte;
}
#endif // !CODA_OSS_NO_std_byte

#endif // CODA_OSS_std_cstddef_INCLUDED_
30 changes: 15 additions & 15 deletions externals/coda-oss/modules/c++/std/include/std/filesystem
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,27 @@
#pragma once

// Make it (too?) easy for clients to get our various std:: implementations

#include "sys/filesystem.h"

#if CODA_OSS_cpp17
// Some versions of G++ say they're C++17 but don't have <filesystem>
#if __has_include(<filesystem>) // __has_include is C++17
#include <filesystem>
#undef CODA_OSS_NO_std_filesystem
#define CODA_OSS_NO_std_filesystem 1 // don't need our own
#endif
#endif

#ifndef CODA_OSS_NO_std_filesystem
#define CODA_OSS_NO_std_filesystem 0 // enabled, unless explicitly disabled
#define CODA_OSS_NO_std_filesystem 0 // enabled, unless explicitly disabled

#include "coda_oss/CPlusPlus.h"
#if CODA_OSS_cpp17
// Some versions of G++ say they're C++17 but don't have <filesystem>
#if __has_include(<filesystem>) // __has_include is C++17
#include <filesystem>
#undef CODA_OSS_NO_std_filesystem
#define CODA_OSS_NO_std_filesystem 1 // don't need our own
#endif
#endif
#endif

#if !CODA_OSS_NO_std_filesystem
namespace std // This is slightly uncouth: we're not supposed to augment "std".
{
namespace filesystem = coda_oss::filesystem;
}
namespace std // This is slightly uncouth: we're not supposed to augment "std".
{
namespace filesystem = coda_oss::filesystem;
}
#endif // !CODA_OSS_NO_std_filesystem

#endif // CODA_OSS_std_filesystem_INCLUDED_
22 changes: 8 additions & 14 deletions externals/coda-oss/modules/c++/std/include/std/memory
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* =========================================================================
* This file is part of sys-c++
* This file is part of std-c++
* =========================================================================
*
* (C) Copyright 2021, Maxar Technologies, Inc.
*
* sys-c++ is free software; you can redistribute it and/or modify
* std-c++ is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
Expand All @@ -25,27 +25,21 @@
#include <memory>

// Make it (too?) easy for clients to get our various std:: implementations

#include "coda_oss/memory.h"

#if defined(__cpp_lib_make_unique) && (__cpp_lib_make_unique >= 201304L) // https://en.cppreference.com/w/cpp/utility/feature_test
#undef CODA_OSS_NO_std_make_unique
#define CODA_OSS_NO_std_make_unique 1 // don't need our own
#endif

#ifndef CODA_OSS_NO_std_make_unique
#define CODA_OSS_NO_std_make_unique 0 // enabled, unless explicitly disabled

#if defined(__cpp_lib_make_unique) && (__cpp_lib_make_unique >= 201304L) // https://en.cppreference.com/w/cpp/utility/feature_test
#undef CODA_OSS_NO_std_make_unique
#define CODA_OSS_NO_std_make_unique 1 // don't need our own
#endif
#endif

#if !CODA_OSS_NO_std_make_unique
namespace std // This is slightly uncouth: we're not supposed to augment "std".
{
template <typename T, typename... TArgs>
std::unique_ptr<T> make_unique(TArgs && ... args)
{
// let coda_oss::make_unique to all the template magic
return coda_oss::make_unique<T>(std::forward<TArgs>(args)...);
}
using coda_oss::make_unique;
}
#endif // !CODA_OSS_NO_std_make_unique

Expand Down
35 changes: 14 additions & 21 deletions externals/coda-oss/modules/c++/std/include/std/optional
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* =========================================================================
* This file is part of sys-c++
* This file is part of std-c++
* =========================================================================
*
* (C) Copyright 2021, Maxar Technologies, Inc.
*
* sys-c++ is free software; you can redistribute it and/or modify
* std-c++ is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
Expand All @@ -23,32 +23,25 @@
#pragma once

// Make it (too?) easy for clients to get our various std:: implementations

#include "coda_oss/optional.h"
static_assert(CODA_OSS_coda_oss_optional >= 201606L, "missing coda_oss::optional");

#include "coda_oss/CPlusPlus.h"
#if CODA_OSS_cpp17
#include <optional>
#undef CODA_OSS_NO_std_optional
#define CODA_OSS_NO_std_optional 1 // don't need our own
#endif

#ifndef CODA_OSS_NO_std_optional
#define CODA_OSS_NO_std_optional 0 // enabled, unless explicitly disabled

#include "coda_oss/CPlusPlus.h"
#if CODA_OSS_cpp17
#include <optional>
#undef CODA_OSS_NO_std_optional
#define CODA_OSS_NO_std_optional 1 // don't need our own
#endif
#endif

#if !CODA_OSS_NO_std_optional
namespace std // This is slightly uncouth: we're not supposed to augment "std".
{
template<typename T>
using optional = coda_oss::optional<T>;
template <typename T, typename... TArgs>
inline optional<T> make_optional(TArgs && ... args)
{
return coda_oss::make_optional<T>(std::forward<TArgs>(args)...);
}
}
namespace std // This is slightly uncouth: we're not supposed to augment "std".
{
using coda_oss::optional;
using coda_oss::make_optional;
}
#endif // !CODA_OSS_NO_std_optional

#endif // CODA_OSS_std_optional_INCLUDED_
Loading

0 comments on commit e93b9e5

Please sign in to comment.