build: satiate clang-tidy somewhat

This commit is contained in:
Danny Robson 2019-01-03 15:48:34 +11:00
parent becd1e24e3
commit b61d55ee3c
20 changed files with 162 additions and 141 deletions

View File

@ -90,8 +90,9 @@ namespace cruft::adapter {
public:
using inner_type = typename std::iterator_traits<IteratorT>::value_type;
using value_type = decltype (std::get<I> (std::declval<inner_type>));
using value_type = decltype (std::get<I> (std::declval<inner_type> ()));
using reference = value_type&;
using const_reference = value_type const&;
explicit scalar (IteratorT _inner):
@ -99,7 +100,7 @@ namespace cruft::adapter {
{ ; }
const reference operator* (void) const&
const_reference operator* (void) const&
{ return std::get<I> (*m_inner); }
reference operator* (void)&

View File

@ -25,7 +25,7 @@ linear::linear (cruft::view<u08*> _data):
///////////////////////////////////////////////////////////////////////////////
linear::linear (linear &&rhs)
linear::linear (linear &&rhs) noexcept
: m_begin (std::exchange (rhs.m_begin, nullptr))
, m_end (std::exchange (rhs.m_end, nullptr))
, m_cursor (std::exchange (rhs.m_cursor, nullptr))
@ -34,7 +34,7 @@ linear::linear (linear &&rhs)
//-----------------------------------------------------------------------------
linear&
linear::operator= (linear &&rhs)
linear::operator= (linear &&rhs) noexcept
{
m_begin = std::exchange (rhs.m_begin, nullptr);
m_end = std::exchange (rhs.m_end, nullptr);

View File

@ -25,8 +25,8 @@ namespace cruft::alloc {
linear (const linear&) = delete;
linear& operator= (const linear&) = delete;
linear (linear&&);
linear& operator= (linear&&);
linear (linear&&) noexcept;
linear& operator= (linear&&) noexcept;
linear (cruft::view<u08*> _data);

View File

@ -3,12 +3,13 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* Copyright 2016-2018 Danny Robson <danny@nerdcruft.net>
* Copyright 2016-2019 Danny Robson <danny@nerdcruft.net>
*/
#pragma once
#include "annotation.hpp"
#include "debug.hpp"
#include <cstdint>
#include <stdexcept>

View File

@ -3,11 +3,10 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* Copyright 2012-2017 Danny Robson <danny@nerdcruft.net>
* Copyright 2012-2019 Danny Robson <danny@nerdcruft.net>
*/
#ifndef CRUFT_UTIL_COORD_BASE_HPP
#define CRUFT_UTIL_COORD_BASE_HPP
#pragma once
#include "fwd.hpp"
@ -254,4 +253,20 @@ namespace cruft::coord {
};
}
#endif
/// Invoke a macro across all typical coordinate parameter combinations.
///
/// ie, each of the types i16, i32, i64, f32, and f64; and arities of 1, 2, 3,
/// and 4.
///
/// This is useful for exhaustive delayed instantiation in .cpp files.
#define MAP_CRUFT_COORD_PARAMS(F) \
F(1,i16) F(2,i16) F(3,i16) F(4,i16) \
F(1,i32) F(2,i32) F(3,i32) F(4,i32) \
F(1,i64) F(2,i64) F(3,i64) F(4,i64) \
F(1,u16) F(2,u16) F(3,u16) F(4,u16) \
F(1,u32) F(2,u32) F(3,u32) F(4,u32) \
F(1,u64) F(2,u64) F(3,u64) F(4,u64) \
F(1,f32) F(2,f32) F(3,f32) F(4,f32) \
F(1,f64) F(2,f64) F(3,f64) F(4,f64)

View File

@ -93,9 +93,9 @@ namespace cruft::debug {
//-----------------------------------------------------------------------------
#define INSTANTIATE_S_T(S,T) \
template struct ::cruft::extent<S,T>; \
template bool ::cruft::debug::is_valid (const ::cruft::extent<S,T>&); \
template struct ::cruft::debug::validator<::cruft::extent<S,T>>;
template struct ::cruft::extent<(S),T>; \
template bool ::cruft::debug::is_valid (const ::cruft::extent<(S),T>&); \
template struct ::cruft::debug::validator<::cruft::extent<(S),T>>;
#define INSTANTIATE(T) \
INSTANTIATE_S_T(1,T) \

View File

@ -60,9 +60,9 @@ struct cruft::debug::validator<ray<S,T>> {
///////////////////////////////////////////////////////////////////////////////
#define INSTANTIATE_S_T(S,T) \
template std::ostream& cruft::geom::operator<< (std::ostream&, ray<S,T>); \
template struct cruft::debug::validator<ray<S,T>>; \
template struct cruft::geom::ray<S,T>;
template std::ostream& cruft::geom::operator<< (std::ostream&, ray<(S),T>); \
template struct cruft::debug::validator<ray<(S),T>>; \
template struct cruft::geom::ray<(S),T>;
INSTANTIATE_S_T(2,float)

View File

@ -86,11 +86,13 @@ murmur2<DigestT>::operator() (cruft::view<const uint8_t*> data) const noexcept
{
static_assert (std::is_same_v<DigestT,uint32_t> || std::is_same_v<DigestT,uint64_t>);
if constexpr (std::is_same_v<DigestT,uint32_t>)
if constexpr (std::is_same_v<DigestT,uint32_t>) {
return hash_32 (data.data (), data.size (), m_seed);
}
if constexpr (std::is_same_v<DigestT,uint64_t>)
if constexpr (std::is_same_v<DigestT,uint64_t>) {
return hash_64 (data.data (), data.size (), m_seed);
}
unreachable ();
}

View File

@ -31,8 +31,8 @@ read_le (const void *ptr)
template <typename T>
struct constants {
static const T prime[5];
static const T round_rotate;
static const T final_rotate[3];
static const T round_rotate;
};

View File

@ -9,6 +9,7 @@
#include "point.hpp"
#include "debug.hpp"
#include "std.hpp"
#include <cstdlib>
@ -58,27 +59,16 @@ cruft::furthest (cruft::view<const cruft::point<S,T>*> src)
}
//-----------------------------------------------------------------------------
///////////////////////////////////////////////////////////////////////////////
#define INSTANTIATE_S_T(S,T) \
template struct cruft::point<S,T>; \
template bool cruft::debug::is_valid (const point<S,T>&); \
template std::pair<cruft::point<S,T>,cruft::point<S,T>> cruft::furthest (cruft::view<const cruft::point<S,T>*>); \
template struct cruft::debug::validator<point<S,T>>;
#define INSTANTIATE(T) \
INSTANTIATE_S_T(1,T) \
INSTANTIATE_S_T(2,T) \
INSTANTIATE_S_T(3,T) \
INSTANTIATE_S_T(4,T)
template struct cruft::point<(S),T>; \
template bool cruft::debug::is_valid (const point<(S),T>&); \
template std::pair< \
cruft::point<(S),T>, \
cruft::point<(S),T> \
> cruft::furthest (cruft::view<const cruft::point<(S),T>*>); \
template struct cruft::debug::validator<point<(S),T>>;
INSTANTIATE(int16_t)
INSTANTIATE(int32_t)
INSTANTIATE(int64_t)
INSTANTIATE(uint16_t)
INSTANTIATE(uint32_t)
INSTANTIATE(uint64_t)
INSTANTIATE(float)
INSTANTIATE(double)
//-----------------------------------------------------------------------------
MAP_CRUFT_COORD_PARAMS(INSTANTIATE_S_T)

View File

@ -102,9 +102,12 @@ template <typename T>
rational<T>
rational<T>::reduced (void) const
{
if (n == 0) {
return { 0, 1 };
}
CHECK_NEZ (d);
auto x = std::gcd (abs (n), abs (d));
return { n / x, d / x };
}

38
tap.hpp
View File

@ -3,13 +3,13 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* Copyright 2015-2017 Danny Robson <danny@nerdcruft.net>
* Copyright 2015-2019 Danny Robson <danny@nerdcruft.net>
*/
#ifndef CRUFT_UTIL_TAP_HPP
#define CRUFT_UTIL_TAP_HPP
#pragma once
#include "debug.hpp"
#include "except.hpp"
#include "format.hpp"
#include "maths.hpp"
@ -45,6 +45,7 @@ namespace cruft::TAP {
logger& operator= (logger const &) = delete;
logger& operator= (logger &&) = delete;
//---------------------------------------------------------------------
template <typename ...Args, size_t N>
bool
@ -223,6 +224,35 @@ namespace cruft::TAP {
int status [[nodiscard]] (void) const;
/// Invoke a FunctionT with a TAP::logger as the first argument, and
/// the remainder forwarded from the provided parameter pack.
///
/// If an exception escapes from the FunctionT the logger will be
/// marked as failed, using a message that attempts to use the raised
/// exception value (else a static generic message if the type isn't
/// easily discoverable).
///
/// Returns the status of the logger provided to the FunctionT.
template <typename FunctionT, typename ...Args>
static auto
run [[nodiscard]] (FunctionT &&function, Args&&...args) noexcept
{
logger tap;
try {
function (tap, args...);
return tap.status ();
} catch (std::exception const &err) {
tap.fail ("no exceptions: %s", err.what ());
} catch (cruft::error const &err) {
tap.fail ("no exceptions: %s", err);
} catch (...) {
tap.fail ("no exceptions");
}
return EXIT_FAILURE;
}
private:
#if !defined(NDEBUG)
mutable int m_reported = -1;
@ -233,5 +263,3 @@ namespace cruft::TAP {
size_t m_size;
};
}
#endif

View File

@ -20,16 +20,16 @@ main (int, char**)
tap.expect_eq (val.capacity (), decltype(val)::elements, "static vs dynamic query for capacity");
{
auto const sum = std::accumulate (val.cbegin (), val.cend (), 0u);
tap.expect_eq (sum, 28u, "accumulate over initializer_list range");
auto const sum = std::accumulate (val.cbegin (), val.cend (), 0);
tap.expect_eq (sum, 28, "accumulate over initializer_list range");
}
{
val.erase (val.begin () + 2);
tap.expect_eq (val.size (), 7u, "erasing removes one element");
auto const sum = std::accumulate (val.cbegin (), val.cend (), 0u);
tap.expect_eq (sum, 26u, "erase one element");
auto const sum = std::accumulate (val.cbegin (), val.cend (), 0);
tap.expect_eq (sum, 26, "erase one element");
}
{
@ -39,8 +39,8 @@ main (int, char**)
// Perform an accumulate to check the rest of the values are there too.
val.insert (val.begin () + 4, 13);
tap.expect_eq (val[4], 13, "inserted values matches indexed value");
auto const sum = std::accumulate (val.cbegin (), val.cend (), 0u);
tap.expect_eq (sum, 39u, "accumulate over new array suggests all still present");
auto const sum = std::accumulate (val.cbegin (), val.cend (), 0);
tap.expect_eq (sum, 39, "accumulate over new array suggests all still present");
}
}

View File

@ -13,8 +13,6 @@
int
main (int, char**)
{
cruft::TAP::logger tap;
static constexpr bool T = true;
static constexpr bool F = false;
@ -49,6 +47,7 @@ main (int, char**)
{ '\n', F, F, F, F, T, 0, 0, "newline" },
};
return cruft::TAP::logger::run ([] (auto &tap) {
#define TRY_BOOL(X) [&] () -> bool { try { return X; } catch (...) { return false; }; } ()
for (auto &t: TESTS) {
@ -69,6 +68,5 @@ main (int, char**)
tap.expect_eq ("6a"_hex2u8, std::vector<uint8_t>({0x6a}), "hex2u8, 1 byte");
tap.expect_eq ("a6"_hex2array, std::array<uint8_t,1> ({0xa6}), "hex2array, 1 byte");
return tap.status ();
});
}

View File

@ -10,7 +10,10 @@ int
main (int, char **) {
cruft::TAP::logger tap;
debug::backtrace ();
// Instantiate a backtrace just so we know that linking has worked.
debug::backtrace foo;
(void)foo;
tap.noop ();
return tap.status ();

View File

@ -249,8 +249,7 @@ test_positional (cruft::TAP::logger &tap)
///////////////////////////////////////////////////////////////////////////////
int
main (int, char **) {
cruft::TAP::logger tap;
return cruft::TAP::logger::run ([] (auto &tap) {
test_null (tap);
test_present (tap);
test_bool (tap);
@ -263,6 +262,5 @@ main (int, char **) {
test_bytes (tap);
test_required (tap);
test_positional (tap);
return tap.status ();
});
}

View File

@ -30,8 +30,7 @@ struct {
int
main (int, char**)
{
cruft::TAP::logger tap;
return cruft::TAP::logger::run ([] (auto &tap) {
for (const auto &t: TESTS) {
#define TEST(KLASS) do { \
auto computed = cruft::hash::KLASS{}(cruft::view {t.dat}.template cast<const uint8_t*> ()); \
@ -44,6 +43,5 @@ main (int, char**)
TEST(crc32d);
TEST(crc64);
}
return tap.status ();
});
}

View File

@ -124,12 +124,10 @@ done:
int
main (int, char **)
{
cruft::TAP::logger tap;
return cruft::TAP::logger::run ([] (auto &tap) {
check_single (tap);
check_unique_ptr (tap);
check_keep_value (tap);
check_keep_variadic_value (tap);
return tap.status ();
});
}

View File

@ -1,5 +1,6 @@
#include "signal.hpp"
#include "except.hpp"
#include "tap.hpp"
@ -124,14 +125,12 @@ test_disconnect (cruft::TAP::logger &tap)
int
main (int, char **)
{
cruft::TAP::logger tap;
return cruft::TAP::logger::run ([] (auto &tap) {
test_null (tap);
test_single (tap);
test_double (tap);
test_value_signal (tap);
test_combiner (tap);
test_disconnect (tap);
return tap.status ();
});
}

View File

@ -9,6 +9,7 @@
#include "vector.hpp"
#include "debug.hpp"
#include "std.hpp"
#include <cmath>
@ -91,24 +92,10 @@ struct cruft::debug::validator<vector<S,T>> {
///////////////////////////////////////////////////////////////////////////////
#define INSTANTIATE_S_T(S,T) \
template struct cruft::vector<S,T>; \
template struct cruft::debug::validator<vector<S,T>>;
#define INSTANTIATE(T) \
INSTANTIATE_S_T(1,T) \
INSTANTIATE_S_T(2,T) \
INSTANTIATE_S_T(3,T) \
INSTANTIATE_S_T(4,T)
INSTANTIATE(uint32_t)
INSTANTIATE(int32_t)
INSTANTIATE(uint64_t)
INSTANTIATE(int64_t)
INSTANTIATE(float)
INSTANTIATE(double)
template struct cruft::vector<(S),T>; \
template struct cruft::debug::validator<vector<(S),T>>;
MAP_CRUFT_COORD_PARAMS(INSTANTIATE_S_T)
//-----------------------------------------------------------------------------
template vector<2,float> cruft::polar_to_cartesian (cruft::vector<2,float>);