build: clang-tidy fixes
This commit is contained in:
parent
92afaf38ec
commit
50b2105df5
@ -14,16 +14,16 @@ namespace cruft::alloc {
|
||||
template <typename ValueT, typename AllocatorT>
|
||||
struct std {
|
||||
using value_type = ValueT;
|
||||
using size_type = std::size_t;
|
||||
using difference_type = std::ptrdiff_t;
|
||||
using size_type = ::std::size_t;
|
||||
using difference_type = ::std::ptrdiff_t;
|
||||
|
||||
[[nodiscard]] ValueT* allocate (std::size_t n)
|
||||
[[nodiscard]] ValueT* allocate (::std::size_t n)
|
||||
{
|
||||
return m_allocator.allocate (n * sizeof (ValueT), alignof (ValueT));
|
||||
}
|
||||
|
||||
void
|
||||
deallocate (ValueT *ptr, std::size_t n)
|
||||
deallocate (ValueT *ptr, ::std::size_t n)
|
||||
{
|
||||
m_allocator.deallocate (ptr, n * sizeof (ValueT), alignof (ValueT));
|
||||
}
|
||||
|
@ -34,10 +34,10 @@ namespace cruft {
|
||||
|
||||
darray (): m_size (0) { ; }
|
||||
darray (darray const&) = default;
|
||||
darray (darray &&) = default;
|
||||
darray (darray &&) noexcept (std::is_trivial_v<ValueT>) = default;
|
||||
|
||||
darray& operator= (darray const&) = default;
|
||||
darray& operator= (darray &&) = default;
|
||||
darray& operator= (darray const&) noexcept (std::is_nothrow_copy_assignable_v<ValueT>) = default;
|
||||
darray& operator= (darray &&) noexcept (std::is_nothrow_move_assignable_v<ValueT>)= default;
|
||||
|
||||
~darray ()
|
||||
{
|
||||
|
@ -92,7 +92,7 @@ namespace cruft {
|
||||
std::array<cruft::point2f, SUBDIV> lookup;
|
||||
|
||||
for (int i = 0; i < SUBDIV; ++i)
|
||||
lookup[i] = eval (i / (SUBDIV - 1.f));
|
||||
lookup[i] = eval (float (i) / (SUBDIV - 1.f));
|
||||
|
||||
size_t best = 0;
|
||||
for (size_t i = 1; i < lookup.size (); ++i) {
|
||||
|
@ -27,9 +27,9 @@ namespace cruft::buffer {
|
||||
~paged ();
|
||||
|
||||
paged (const paged&) = delete;
|
||||
paged (paged &&);
|
||||
paged (paged &&) noexcept;
|
||||
paged& operator= (const paged&) = delete;
|
||||
paged& operator= (paged &&);
|
||||
paged& operator= (paged &&) noexcept;
|
||||
|
||||
value_type* begin (void)&;
|
||||
value_type* end (void)&;
|
||||
|
@ -31,9 +31,9 @@ namespace cruft::buffer {
|
||||
explicit simple (size_t _size);
|
||||
|
||||
simple (const simple&) = delete;
|
||||
simple (simple &&) = default;
|
||||
simple (simple &&) noexcept = default;
|
||||
simple& operator= (const simple&) = delete;
|
||||
simple& operator= (simple &&);
|
||||
simple& operator= (simple &&) noexcept;
|
||||
|
||||
value_type* begin (void)&;
|
||||
value_type* end (void)&;
|
||||
|
12
cmdopt.hpp
12
cmdopt.hpp
@ -313,29 +313,29 @@ namespace cruft::cmdopt {
|
||||
public:
|
||||
template <typename T, typename ...Args>
|
||||
T& add (char shortname,
|
||||
std::string longname,
|
||||
std::string description,
|
||||
std::string const &longname,
|
||||
std::string const &description,
|
||||
Args&&... args)
|
||||
{
|
||||
auto handler = std::make_unique<T> (std::forward<Args> (args)...);
|
||||
T& ref = *handler;
|
||||
|
||||
m_short.insert({ shortname, ref });
|
||||
m_long.insert({ std::move (longname), ref });
|
||||
m_long.insert({ longname, ref });
|
||||
|
||||
m_options.push_back ({ std::move (description), std::move (handler) });
|
||||
m_options.push_back ({ description, std::move (handler) });
|
||||
|
||||
return ref;
|
||||
}
|
||||
|
||||
template <typename T, typename ...Args>
|
||||
T&
|
||||
append (std::string description, Args&&...args)
|
||||
append (std::string const &description, Args&&...args)
|
||||
{
|
||||
auto handler = std::make_unique<T> (std::forward<Args> (args)...);
|
||||
auto &ref = *handler;
|
||||
m_positional.push_back (ref);
|
||||
m_options.push_back ({ std::move (description), std::move (handler) });
|
||||
m_options.push_back ({ description, std::move (handler) });
|
||||
return ref;
|
||||
}
|
||||
|
||||
|
@ -89,12 +89,12 @@ namespace cruft {
|
||||
template <size_t S, typename T>
|
||||
struct redim_type<
|
||||
srgba<S,T>
|
||||
> { template <size_t _S> using type = srgba<_S,T>; };
|
||||
> { template <size_t S_> using type = srgba<S_, T>; };
|
||||
|
||||
template <size_t S, typename T>
|
||||
struct revalue_type<srgba<S,T>> {
|
||||
template <typename _T>
|
||||
using type = srgba<S,_T>;
|
||||
template <typename T_>
|
||||
using type = srgba<S,T_>;
|
||||
};
|
||||
|
||||
|
||||
|
@ -24,7 +24,7 @@ namespace cruft {
|
||||
auto const pos = std::find (
|
||||
std::cbegin (container),
|
||||
std::cend (container),
|
||||
std::move (value)
|
||||
std::forward<ValueT> (value)
|
||||
);
|
||||
|
||||
return pos != std::cend (container);
|
||||
|
@ -148,13 +148,13 @@ namespace cruft {
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
template <std::size_t S, typename T> struct redim_type<point<S,T>>
|
||||
{ template <std::size_t _S> using type = point<_S,T>; };
|
||||
{ template <std::size_t S_> using type = point<S_,T>; };
|
||||
|
||||
template <std::size_t S, typename T> struct redim_type<vector<S,T>>
|
||||
{ template <std::size_t _S> using type = vector<_S,T>; };
|
||||
{ template <std::size_t S_> using type = vector<S_,T>; };
|
||||
|
||||
template <std::size_t S, typename T> struct redim_type<extent<S,T>>
|
||||
{ template <std::size_t _S> using type = extent<_S,T>; };
|
||||
{ template <std::size_t S_> using type = extent<S_,T>; };
|
||||
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
|
@ -140,7 +140,7 @@ x86::x86 ()
|
||||
if (auto const apic_id_size = from_bits (size_identifiers.c, 15, 12); apic_id_size) {
|
||||
cores.physical = 1 << (apic_id_size - 1);
|
||||
} else {
|
||||
cores.physical = (size_identifiers.c & 0xff) + 1;
|
||||
cores.physical = cruft::cast::lossless<int> (size_identifiers.c & 0xff) + 1;
|
||||
}
|
||||
} else {
|
||||
cores.physical = 0;
|
||||
|
12
expected.hpp
12
expected.hpp
@ -26,8 +26,14 @@ namespace cruft {
|
||||
template <typename ErrorT>
|
||||
class unexpected {
|
||||
public:
|
||||
unexpected (ErrorT && _value): m_value (std::move (_value)) { ; }
|
||||
unexpected (ErrorT const &_value): m_value (_value) { ; }
|
||||
unexpected (ErrorT && _value)
|
||||
noexcept (std::is_nothrow_constructible_v<ErrorT>)
|
||||
: m_value (std::move (_value))
|
||||
{ ; }
|
||||
|
||||
unexpected (ErrorT const &_value)
|
||||
: m_value (_value)
|
||||
{ ; }
|
||||
|
||||
ErrorT& value (void)& { return m_value; }
|
||||
ErrorT&& value (void)&& { return std::move (m_value); }
|
||||
@ -58,7 +64,7 @@ namespace cruft {
|
||||
}
|
||||
}
|
||||
|
||||
expected& operator=(expected &&);
|
||||
expected& operator=(expected &&) noexcept (std::is_trivially_move_assignable_v<ValueT>);
|
||||
expected (expected const&);
|
||||
expected& operator=(expected const&);
|
||||
|
||||
|
@ -1 +0,0 @@
|
||||
#include "filesystem.hpp"
|
@ -1,113 +0,0 @@
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* 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 Danny Robson <danny@nerdcruft.net>
|
||||
*/
|
||||
|
||||
#include "filesystem.hpp"
|
||||
|
||||
#include "../../except.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace ns = std::filesystem;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
ns::path::path ()
|
||||
{ ; }
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
ns::path::path (const path &p):
|
||||
m_path (p.m_path)
|
||||
{ ; }
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
std::string
|
||||
ns::path::string (void) const
|
||||
{
|
||||
return m_path;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
const ns::path::string_type&
|
||||
ns::path::native (void) const
|
||||
{
|
||||
return m_path;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
const ns::path::value_type*
|
||||
ns::path::c_str (void) const
|
||||
{
|
||||
return m_path.c_str ();
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
ns::path
|
||||
ns::path::filename (void) const
|
||||
{
|
||||
auto slash = m_path.find_last_of (preferred_separator);
|
||||
if (slash == decltype(m_path)::npos)
|
||||
return m_path;
|
||||
return ns::path (m_path.cbegin () + slash, m_path.cend ());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
ns::path
|
||||
ns::path::stem (void) const
|
||||
{
|
||||
auto name = filename ();
|
||||
|
||||
auto first = name.m_path.cbegin ();
|
||||
auto last = std::find_if (first, name.m_path.cend (), [] (auto c) { return c == '.'; });
|
||||
return path (first, last);
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
ns::path
|
||||
ns::operator/ (const ns::path &a, const ns::path &b)
|
||||
{
|
||||
return ns::path (a) /= b;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
ns::path&
|
||||
ns::path::operator/= (const path &rhs)
|
||||
{
|
||||
m_path += preferred_separator + rhs.m_path;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
bool
|
||||
ns::operator== (const path &a, const path &b)
|
||||
{
|
||||
return a == b;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
bool
|
||||
ns::is_directory (const path &p)
|
||||
{
|
||||
struct stat buf;
|
||||
|
||||
if (stat (p.c_str (), &buf))
|
||||
::cruft::errno_error::throw_code ();
|
||||
|
||||
return S_ISDIR (buf.st_mode);
|
||||
}
|
@ -1,66 +0,0 @@
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* 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 Danny Robson <danny@nerdcruft.net>
|
||||
*/
|
||||
|
||||
#ifndef CRUFT_UTIL_FIXUP_EXPERIMENTAL_FILESYSTEM_HPP
|
||||
#define CRUFT_UTIL_FIXUP_EXPERIMENTAL_FILESYSTEM_HPP
|
||||
|
||||
#include <string>
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
namespace std::filesystem {
|
||||
class path {
|
||||
public:
|
||||
using value_type = char;
|
||||
using string_type = std::basic_string<value_type>;
|
||||
|
||||
static constexpr value_type preferred_separator = '/';
|
||||
|
||||
path ();
|
||||
explicit path (const path&);
|
||||
|
||||
template <class Source>
|
||||
path (const Source &s):
|
||||
m_path (s)
|
||||
{ ; }
|
||||
|
||||
template <class InputT>
|
||||
path (InputT first, InputT last):
|
||||
m_path (first, last)
|
||||
{ ; }
|
||||
|
||||
std::string string (void) const;
|
||||
|
||||
const string_type& native (void) const;
|
||||
const value_type* c_str (void) const;
|
||||
|
||||
path filename (void) const;
|
||||
path stem (void) const;
|
||||
|
||||
path& operator/= (const path&);
|
||||
|
||||
private:
|
||||
string_type m_path;
|
||||
};
|
||||
|
||||
path operator/ (const path&, const path&);
|
||||
|
||||
bool operator== (const path&, const path&);
|
||||
|
||||
//bool is_directory (file_status);
|
||||
bool is_directory (const path&);
|
||||
//bool is_directory (const path&, error_code&);
|
||||
|
||||
template <class CharT, class Traits>
|
||||
std::basic_ostream<CharT,Traits>&
|
||||
operator<< (std::basic_ostream<CharT,Traits> &os, const path &p)
|
||||
{ return os << p.native (); }
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
@ -57,8 +57,8 @@ namespace cruft::geom {
|
||||
template <size_t,typename> class A,
|
||||
template <size_t,typename> class B,
|
||||
typename = std::enable_if_t<
|
||||
!std::is_same_v<cruft::point<S,T>, A> &&
|
||||
!std::is_same_v<cruft::point<S,T>, B>
|
||||
!std::is_same_v<cruft::point<S,T>, A<S,T>> &&
|
||||
!std::is_same_v<cruft::point<S,T>, B<S,T>>
|
||||
>
|
||||
>
|
||||
T
|
||||
|
@ -65,7 +65,7 @@ namespace cruft::hash {
|
||||
buzhash (buzhash const&) = default;
|
||||
buzhash (buzhash &&) noexcept = default;
|
||||
buzhash& operator= (buzhash const&) = default;
|
||||
buzhash& operator= (buzhash &&) = default;
|
||||
buzhash& operator= (buzhash &&) noexcept = default;
|
||||
|
||||
/// Rotate the hash over a pointer to the buffer we've been operating
|
||||
/// on.
|
||||
|
@ -22,7 +22,7 @@ library::library (const std::filesystem::path &path):
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
library::library (library &&rhs):
|
||||
library::library (library &&rhs) noexcept:
|
||||
m_handle (nullptr)
|
||||
{
|
||||
std::swap (m_handle, rhs.m_handle);
|
||||
@ -31,7 +31,7 @@ library::library (library &&rhs):
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
library&
|
||||
library::operator= (cruft::library &&rhs)
|
||||
library::operator= (cruft::library &&rhs) noexcept
|
||||
{
|
||||
std::swap (m_handle, rhs.m_handle);
|
||||
return *this;
|
||||
|
@ -22,8 +22,8 @@ namespace cruft {
|
||||
explicit library (const std::filesystem::path&);
|
||||
library (library const&) = delete;
|
||||
library& operator=(library const&) = delete;
|
||||
library (library&&);
|
||||
library& operator= (library&&);
|
||||
library (library&&) noexcept;
|
||||
library& operator= (library&&) noexcept;
|
||||
|
||||
~library ();
|
||||
|
||||
|
@ -87,7 +87,7 @@ namespace cruft::parallel {
|
||||
/// the value `false` will be returned.
|
||||
///
|
||||
/// NOTE: There are no exception guarantees at this time.
|
||||
bool pop (ValueT *out)
|
||||
bool pop [[nodiscard]] (ValueT *out)
|
||||
{
|
||||
std::lock_guard lk (m_lock);
|
||||
if (m_cursor == 0)
|
||||
@ -109,7 +109,7 @@ namespace cruft::parallel {
|
||||
///
|
||||
/// NOTE: There are no exception guarantees at this time.
|
||||
template <typename InputT>
|
||||
bool push (InputT &&arg)
|
||||
bool push [[nodiscard]] (InputT &&arg)
|
||||
{
|
||||
std::lock_guard lk (m_lock);
|
||||
if (m_cursor >= m_store.size ())
|
||||
|
@ -51,11 +51,11 @@ enum plural_t {
|
||||
/// \param prefix The prefix we are checking for.
|
||||
/// \param plural Whether to (optionall) perform pluralisation on the prefix.
|
||||
/// \return True IFF the prefix was found and the view was updated.
|
||||
template <std::size_t _N, std::size_t N = _N - 1>
|
||||
template <std::size_t N_, std::size_t N = N_ - 1>
|
||||
static bool
|
||||
try_consume_prefix (
|
||||
cruft::view<char const*> &str,
|
||||
char const (&prefix)[_N],
|
||||
char const (&prefix)[N_],
|
||||
plural_t plural = SINGULAR)
|
||||
{
|
||||
static_assert (N > 0);
|
||||
|
@ -37,7 +37,7 @@ namespace cruft::ptr {
|
||||
thin (thin const&) = delete;
|
||||
thin& operator= (thin const&) = delete;
|
||||
|
||||
thin (thin &&rhs)
|
||||
thin (thin &&rhs) noexcept
|
||||
: m_value (rhs.m_value)
|
||||
{ rhs.m_value = nullptr; }
|
||||
|
||||
|
8
pool.hpp
8
pool.hpp
@ -63,7 +63,7 @@ namespace cruft {
|
||||
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
pool& operator= (pool &&rhs)
|
||||
pool& operator= (pool &&rhs) noexcept
|
||||
{
|
||||
std::swap (m_available, rhs.m_available);
|
||||
std::swap (m_store, rhs.m_store);
|
||||
@ -268,7 +268,11 @@ namespace cruft {
|
||||
|
||||
T* elements = reinterpret_cast<T*> (m_store);
|
||||
for (size_t i = m_capacity; i--; )
|
||||
m_available.push (elements + i);
|
||||
// The available indices _should_ have enough capacity at all
|
||||
// times as we've presumably allocated it at construction time,
|
||||
// but it's worthwhile checking anyway.
|
||||
if (!m_available.push (elements + i)) [[unlikely]]
|
||||
throw std::bad_alloc ();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ cruft::posix::stat (char const *path)
|
||||
struct ::stat
|
||||
cruft::posix::stat (std::filesystem::path const &path)
|
||||
{
|
||||
return stat (path.u8string ().c_str ());
|
||||
return stat (reinterpret_cast<char const*> (path.u8string ().c_str ()));
|
||||
}
|
||||
|
||||
|
||||
|
@ -3,13 +3,14 @@
|
||||
* 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 2020, Danny Robson <danny@nerdcruft.net>
|
||||
* Copyright 2020-2021, Danny Robson <danny@nerdcruft.net>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "uniform.hpp"
|
||||
|
||||
#include <optional>
|
||||
#include <type_traits>
|
||||
|
||||
|
||||
@ -43,7 +44,7 @@ namespace cruft::rand::distribution {
|
||||
|
||||
void reset (void)
|
||||
{
|
||||
m_live = false;
|
||||
m_prev.reset ();
|
||||
}
|
||||
|
||||
|
||||
@ -61,9 +62,10 @@ namespace cruft::rand::distribution {
|
||||
result_type
|
||||
operator() (GeneratorT &&g, param_type const ¶ms)
|
||||
{
|
||||
if (m_live) {
|
||||
m_live = false;
|
||||
return m_prev * params.stddev + params.mean;
|
||||
if (m_prev) {
|
||||
auto const res = m_prev.value () * params.stddev + params.mean;
|
||||
m_prev.reset ();
|
||||
return res;
|
||||
}
|
||||
|
||||
auto [u, v, s] = find_uvs (g);
|
||||
@ -71,7 +73,6 @@ namespace cruft::rand::distribution {
|
||||
result_type z1 = v * std::sqrt (-2 * std::log (s) / s);
|
||||
|
||||
m_prev = z1;
|
||||
m_live = true;
|
||||
|
||||
return z0 * params.stddev + params.mean;
|
||||
}
|
||||
@ -101,7 +102,6 @@ namespace cruft::rand::distribution {
|
||||
}
|
||||
|
||||
param_type m_param;
|
||||
bool m_live = false;
|
||||
result_type m_prev;
|
||||
std::optional<result_type> m_prev;
|
||||
};
|
||||
}
|
||||
|
@ -13,6 +13,8 @@
|
||||
#include "maths.hpp"
|
||||
#include "random.hpp"
|
||||
|
||||
#include <ostream>
|
||||
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
|
||||
|
@ -42,7 +42,11 @@ namespace cruft {
|
||||
|
||||
~cookie ()
|
||||
{
|
||||
registry::remove (m_key);
|
||||
try {
|
||||
registry::remove (m_key);
|
||||
} catch (std::exception const &err) {
|
||||
LOG_ERROR ("Unable to remove registration for {}", m_key);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -82,8 +82,8 @@ namespace cruft::scoped {
|
||||
m_args (std::forward<Args> (_args)...)
|
||||
{ ; }
|
||||
|
||||
function (function&&);
|
||||
function (const function&);
|
||||
function (function&&) noexcept;
|
||||
function (function const&);
|
||||
|
||||
~function ()
|
||||
{
|
||||
|
@ -34,11 +34,11 @@ namespace cruft::strongdef {
|
||||
|
||||
constexpr explicit index (cruft::types::identity_t<T> const &_data): data (_data) { ; }
|
||||
constexpr index (index const&) = default;
|
||||
constexpr index (index &&) = default;
|
||||
constexpr index (index &&) noexcept (std::is_nothrow_constructible_v<T>) = default;
|
||||
|
||||
index& operator= (T const &) = delete;
|
||||
index& operator= (index const &) = default;
|
||||
index& operator= (index &&) = default;
|
||||
index& operator= (index &&) noexcept (std::is_nothrow_copy_assignable_v<T>) = default;
|
||||
|
||||
// conversion operators must not be explicit or it defeats the point
|
||||
// of this class (ease of use, transparency).
|
||||
|
@ -27,14 +27,14 @@ int main ()
|
||||
{
|
||||
static constexpr int COUNT = 4;
|
||||
cruft::parallel::stack<int> values (COUNT);
|
||||
for (int i = 0; i < COUNT; ++i)
|
||||
values.push (i);
|
||||
|
||||
bool success = true;
|
||||
for (int i = COUNT - 1; i >= 0; --i) {
|
||||
int res = -1;
|
||||
values.pop (&res);
|
||||
for (int i = 0; i < COUNT; ++i)
|
||||
success = success && values.push (i);
|
||||
|
||||
for (int i = COUNT - 1; success && i >= 0; --i) {
|
||||
int res = -1;
|
||||
success = success && values.pop (&res);
|
||||
success = success && res == i;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user