File: is_empty.hpp

package info (click to toggle)
reflect-cpp 0.18.0%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 12,524 kB
  • sloc: cpp: 44,484; python: 131; makefile: 30; sh: 3
file content (42 lines) | stat: -rw-r--r-- 1,156 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#ifndef RFL_PARSING_IS_EMPTY_HPP_
#define RFL_PARSING_IS_EMPTY_HPP_

#include <type_traits>

#include "../internal/has_reflection_method_v.hpp"
#include "../internal/has_reflection_type_v.hpp"
#include "../internal/is_rename.hpp"
#include "../internal/is_skip.hpp"
#include "is_map_like.hpp"
#include "is_vector_like.hpp"

namespace rfl {
namespace parsing {

template <class T>
static bool is_empty(const T& _var) {
  using Type = std::remove_cvref_t<T>;
  if constexpr (std::is_pointer_v<Type>) {
    return !_var || is_empty(*_var);
  } else if constexpr (internal::is_skip_v<Type>) {
    return Type::skip_serialization_;
  } else if constexpr (internal::has_reflection_type_v<Type>) {
    if constexpr (internal::has_reflection_method_v<Type>) {
      return is_empty(_var.reflection());
    } else {
      const auto& [r] = _var;
      return is_empty(r);
    }
  } else if constexpr (internal::is_rename_v<Type>) {
    return is_empty(_var.value());
  } else if constexpr (is_map_like_v<Type> || is_vector_like_v<Type>) {
    return _var.begin() == _var.end();
  } else {
    return !_var;
  }
}

}  // namespace parsing
}  // namespace rfl

#endif