Przeglądaj źródła

added the pair type (mostly std conformant)

devel
Ludovic 'Archivist' Lagouardette 3 lat temu
rodzic
commit
25f2f4769b
5 zmienionych plików z 117 dodań i 1 usunięć
  1. +6
    -0
      .vscode/settings.json
  2. +1
    -1
      Makefile
  3. +72
    -0
      include/gp/pair.hpp
  4. +1
    -0
      tests.cpp
  5. +37
    -0
      tests/pair_test.cpp

+ 6
- 0
.vscode/settings.json Wyświetl plik

@ -0,0 +1,6 @@
{
"clang.cflags": [
"-std=c++17",
"-I${workspaceRoot}/include"
]
}

+ 1
- 1
Makefile Wyświetl plik

@ -1,4 +1,4 @@
CXX= clang++-8
CXX= clang++-10
CXXFLAGS= --std=c++17 -O0 -pthread -DFUZZ_STRENGTH=500000 \
-Wno-unknown-attributes \
-g -fprofile-instr-generate -fcoverage-mapping

+ 72
- 0
include/gp/pair.hpp Wyświetl plik

@ -0,0 +1,72 @@
#pragma once
#include "gp/algorithm/move.hpp"
namespace gp{
template<typename T1, typename T2>
struct pair{
T1 first;
T2 second;
pair() : first(), second() {}
pair(const T1& a, const T2& b) : first(a), second(b) {}
pair(pair&& v)
: first(gp::move(v.first))
, second(gp::move(v.second))
{}
template<typename U1, typename U2>
pair(U1&& a, U2&& b)
: first(gp::forward<U1>(a))
, second(gp::forward<U2>(b))
{}
template<typename U1, typename U2>
pair(pair<U1, U2>&& v)
: first(gp::move(v.first))
, second(gp::move(v.second))
{}
pair& operator=(pair&& v)
{
first = gp::move(v.first);
second = gp::move(v.second);
return *this;
}
bool operator==(const pair& rhs) {
return first == rhs.first and second == rhs.second;
}
bool operator!=(const pair& rhs) {
return first != rhs.first or second != rhs.second;
}
bool operator<=(const pair& rhs) {
if(first > rhs.first) {
return false;
} else if(first == rhs.first) {
return second <= rhs.second;
}
return true;
}
bool operator>=(const pair& rhs) {
if(first < rhs.first) {
return false;
} else if(first == rhs.first) {
return second >= rhs.second;
}
return true;
}
bool operator<(const pair& rhs) {
return !(*this >= rhs);
}
bool operator>(const pair& rhs) {
return !(*this <= rhs);
}
};
}

+ 1
- 0
tests.cpp Wyświetl plik

@ -4,6 +4,7 @@
#include "gp_test.cpp"
#include "bloomfilter.cpp"
#include "quotient_filter.cpp"
#include "pair_test.cpp"
#include <iostream>
alignas(2048) gp::array<char, 4096> static_mapper::store;

+ 37
- 0
tests/pair_test.cpp Wyświetl plik

@ -0,0 +1,37 @@
#include "test_scaffold.h"
#include <random>
#include <string>
#include "gp/pair.hpp"
typedef std::mt19937_64 cheap_rand;
struct pair_test : public test_scaffold {
uint32_t seed;
pair_test() {
seed = std::random_device{}();
name = __FILE__ ":1_seed";
name += std::to_string(seed);
}
virtual int run() {
cheap_rand setter(seed);
cheap_rand getter(seed);
gp::pair<double, std::string> v{0, "zero"};
bool result = true;
for(int i = 0 ; i < 100; i++)
{
auto a = setter();
auto b = setter();
v = gp::pair(a, std::to_string(a));
result = gp::pair<double, std::string>(b, std::to_string(b)) == v ? result : false;
}
return !result;
}
};
append_test dummy_rsly21r43(new pair_test{});

Ładowanie…
Anuluj
Zapisz