ChaiScript
function_params.hpp
1 // This file is distributed under the BSD License.
2 // See "license.txt" for details.
3 // Copyright 2009-2012, Jonathan Turner (jonathan@emptycrate.com)
4 // Copyright 2009-2017, Jason Turner (jason@emptycrate.com)
5 // http://www.chaiscript.com
6 
7 // This is an open source non-commercial project. Dear PVS-Studio, please check it.
8 // PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
9 
10 #ifndef CHAISCRIPT_FUNCTION_PARAMS_HPP
11 #define CHAISCRIPT_FUNCTION_PARAMS_HPP
12 
13 #include "boxed_value.hpp"
14 
15 namespace chaiscript {
17  public:
18  constexpr Function_Params(const Boxed_Value *const t_begin, const Boxed_Value *const t_end)
19  : m_begin(t_begin)
20  , m_end(t_end) {
21  }
22 
23  explicit Function_Params(const Boxed_Value &bv)
24  : m_begin(&bv)
25  , m_end(m_begin + 1) {
26  }
27 
28  explicit Function_Params(const std::vector<Boxed_Value> &vec)
29  : m_begin(vec.empty() ? nullptr : &vec.front())
30  , m_end(vec.empty() ? nullptr : &vec.front() + vec.size()) {
31  }
32 
33  template<size_t Size>
34  constexpr explicit Function_Params(const std::array<Boxed_Value, Size> &a)
35  : m_begin(&a.front())
36  , m_end(&a.front() + Size) {
37  }
38 
39  [[nodiscard]] constexpr const Boxed_Value &operator[](const std::size_t t_i) const noexcept { return m_begin[t_i]; }
40 
41  [[nodiscard]] constexpr const Boxed_Value *begin() const noexcept { return m_begin; }
42 
43  [[nodiscard]] constexpr const Boxed_Value &front() const noexcept { return *m_begin; }
44 
45  [[nodiscard]] constexpr const Boxed_Value *end() const noexcept { return m_end; }
46 
47  [[nodiscard]] constexpr std::size_t size() const noexcept { return std::size_t(m_end - m_begin); }
48 
49  [[nodiscard]] std::vector<Boxed_Value> to_vector() const { return std::vector<Boxed_Value>{m_begin, m_end}; }
50 
51  [[nodiscard]] constexpr bool empty() const noexcept { return m_begin == m_end; }
52 
53  private:
54  const Boxed_Value *m_begin = nullptr;
55  const Boxed_Value *m_end = nullptr;
56  };
57 
58  // Constructor specialization for array of size 0
59  template<>
60  constexpr Function_Params::Function_Params(const std::array<Boxed_Value, size_t{0}> & /* a */)
61  : m_begin(nullptr)
62  , m_end(nullptr) {
63  }
64 
65 } // namespace chaiscript
66 
67 #endif
Namespace chaiscript contains every API call that the average user will be concerned with...
Definition: function_params.hpp:16
A wrapper for holding any valid C++ type.
Definition: boxed_value.hpp:24