Luanti 5.11.0-dev
 
Loading...
Searching...
No Matches
basic_macros.h
Go to the documentation of this file.
1// Luanti
2// SPDX-License-Identifier: LGPL-2.1-or-later
3// Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5#pragma once
6
7#define ARRLEN(x) (sizeof(x) / sizeof((x)[0]))
8
9#define MYMIN(a, b) ((a) < (b) ? (a) : (b))
10
11#define MYMAX(a, b) ((a) > (b) ? (a) : (b))
12
13// Requires <algorithm>
14#define CONTAINS(c, v) (std::find((c).begin(), (c).end(), (v)) != (c).end())
15
16// Requires <algorithm>
17#define SORT_AND_UNIQUE(c) do { \
18 std::sort((c).begin(), (c).end()); \
19 (c).erase(std::unique((c).begin(), (c).end()), (c).end()); \
20 } while (0)
21
22// To disable copy constructors and assignment operations for some class
23// 'Foobar', add the macro DISABLE_CLASS_COPY(Foobar) in the class definition.
24// Note this also disables copying for any classes derived from 'Foobar' as well
25// as classes having a 'Foobar' member.
26#define DISABLE_CLASS_COPY(C) \
27 C(const C &) = delete; \
28 C &operator=(const C &) = delete;
29
30// If you have used DISABLE_CLASS_COPY with a class but still want to permit moving
31// use this macro to add the default move constructors back.
32#define ALLOW_CLASS_MOVE(C) \
33 C(C &&other) = default; \
34 C &operator=(C &&) = default;
35