Skip to content

Commit

Permalink
Merge branch 'felixguendling:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex-W4 authored Oct 31, 2024
2 parents 347f524 + 5b6808f commit 35b9902
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
12 changes: 11 additions & 1 deletion include/cista/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,19 @@ struct buffer final {
buffer(buffer const&) = delete;
buffer& operator=(buffer const&) = delete;

buffer(buffer&& o) noexcept : buf_(o.buf_), size_(o.size_) { o.reset(); }
buffer(buffer&& o) noexcept : buf_(o.buf_), size_(o.size_) {
if (&o != this) {
o.reset();
}
}

buffer& operator=(buffer&& o) noexcept {
if (&o == this) {
return *this;
}
if (buf_ != nullptr) {
std::free(buf_);
}
buf_ = o.buf_;
size_ = o.size_;
o.reset();
Expand Down
10 changes: 9 additions & 1 deletion include/cista/hashing.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,14 @@ struct hashing<std::chrono::duration<Rep, Period>> {
}
};

template <typename Clock, typename Duration>
struct hashing<std::chrono::time_point<Clock, Duration>> {
hash_t operator()(std::chrono::time_point<Clock, Duration> const& el,
hash_t const seed = BASE_HASH) {
return hashing<Duration>{}(el.time_since_epoch(), seed);
}
};

template <typename T1, typename T2>
struct hashing<std::pair<T1, T2>> {
constexpr hash_t operator()(std::pair<T1, T2> const& el,
Expand Down Expand Up @@ -171,7 +179,7 @@ struct hashing<std::tuple<Args...>> {
hash_t h = seed;
std::apply(
[&h](auto&&... args) {
((h = hashing<decltype(args)>{}(args, h)), ...);
((h = hashing<std::decay_t<decltype(args)>>{}(args, h)), ...);
},
el);
return h;
Expand Down
3 changes: 2 additions & 1 deletion include/cista/targets/file.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,8 @@ struct file {

file(char const* path, char const* mode)
: f_{std::fopen(path, mode)}, size_{size()} {
verify(f_ != nullptr, "unable to open file");
verify(f_ != nullptr, std::string{"unable to open file: "} + path +
" [mode=" + mode + "]");
}

~file() {
Expand Down
5 changes: 3 additions & 2 deletions include/cista/verify.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#pragma once

#include <stdexcept>
#include <string>

#include "cista/cista_exception.h"
#include "cista/exception.h"

namespace cista {

inline void verify(bool const condition, char const* msg) {
inline void verify(bool const condition, std::string msg) {
if (!condition) {
throw_exception(cista_exception{msg});
throw_exception(cista_exception{std::move(msg)});
}
}

Expand Down

0 comments on commit 35b9902

Please sign in to comment.