Skip to content

Instantly share code, notes, and snippets.

namespace type_traits_internal {
// is_trivially_copyable()
//
// Determines whether the passed type `T` is trivially copyable.
//
// This metafunction is designed to be a drop-in replacement for the C++11
// `std::is_trivially_copyable()` metafunction for platforms that have
// incomplete C++11 support (such as libstdc++ 4.x). We use the C++17 definition
// of TriviallyCopyable.
//
// flag.h
template <typename T>
class Flag {
public:
T Get() const {
// See implementation notes in CommandLineFlag::Get().
union U {
T value;
U() {}
~U() { value.~T(); }
// The minimum atomic size we believe to generate lock free code, i.e. all
// trivially copyable types not bigger this size generate lock free code.
static constexpr int kMinLockFreeAtomicSize = 8;
// The same as kMinLockFreeAtomicSize but maximum atomic size. As double words
// might use two registers, we want to dispatch the logic for them.
#if defined(ABSL_FLAGS_INTERNAL_ATOMIC_DOUBLE_WORD)
static constexpr int kMaxLockFreeAtomicSize = 16;
#else
static constexpr int kMaxLockFreeAtomicSize = 8;
size_t CalcScore(const Problem& p, const std::vector<size_t>& hint) {
MPSolver solver("solving_all_cases", absl::GetFlag(FLAGS_scan_mip_solver_type));
const double infinity = solver.infinity();
std::vector<MPVariable*> books_vars;
std::vector<size_t> books_vars_hints(15000);
std::vector<MPVariable*> clauses_vars;
for (size_t i = 0; i < 15000; ++i) {
books_vars.push_back(solver.MakeBoolVar(absl::StrCat("x_", i)));
}
std::vector<std::pair<const MPVariable*, double>> hinting;
15000
162 14
1120 1119 1118 1117 1116 1115 1114 1113 1112 1111 1110 1109 1108 1107
8081 14
42909 42908 42907 42906 25569 40230 42905 42904 42903 25135 42902 8130 35500 42901
29848 13
58849 17260 75998 72732 70408 45576 76698 53832 37343 14247 72153 33352 78524
8540 13
44713 44712 2873 44711 17616 17452 44710 44709 44708 29596 39123 27996 44707
22086 13
size_t CalcScore(const Problem& p, const std::vector<size_t>& order) {
MPSolver solver("solving_all_cases",
MPSolver::SCIP_MIXED_INTEGER_PROGRAMMING);
std::vector<MPVariable*> books_vars;
std::vector<std::vector<MPVariable*>> libraries_vars;
const double infinity = solver.infinity();
for (size_t i = 0; i < p.books_num; ++i) {
books_vars.push_back(solver.MakeBoolVar(absl::StrCat("x_", i)));
}
for (const size_t ind : order) {
@danlark1
danlark1 / pair_easy.h
Created April 13, 2020 10:55
iteration
std::unordered_map<std::string, int> m;
// ...
for (const auto& [key, value] : m) {
// ...
}
constexpr std::pair<int, int> t;
static_assert(t.first == 0 && t.second == 0);
std::array<int, 5> arr;
// assert(arr[0] == 0); // Undefined behavior
template <typename T, typename U>
struct pair {
T first;
U second;
constexpr std::strong_ordering operator<=>(const pair& other) const {
if (auto first_comp = first <=> other.first; first_comp != 0) {
return first_comp;
} else {
return second <=> other.second;
template <class T>
T Deserialize(const void* memory) {
T t;
memcpy(&t, memory, sizeof(T));
return t;
}
template <class T>
void Serialize(const T& t, void* memory) {
memcpy(memory, &t, sizeof(T));