MCPcopy Create free account
hub / github.com/ChaiScript/ChaiScript / array

Function array

include/chaiscript/dispatchkit/bootstrap.hpp:23–56  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

21 {
22 template<typename T, typename = typename std::enable_if<std::is_array<T>::value>::type >
23 void array(const std::string &type, Module& m)
24 {
25 typedef typename std::remove_extent<T>::type ReturnType;
26 m.add(user_type<T>(), type);
27 m.add(fun(
28 [](T& t, size_t index)->ReturnType &{
29 constexpr auto extent = std::extent<T>::value;
30 if (extent > 0 && index >= extent) {
31 throw std::range_error("Array index out of range. Received: " + std::to_string(index) + " expected < " + std::to_string(extent));
32 } else {
33 return t[index];
34 }
35 }
36 ), "[]"
37 );
38
39 m.add(fun(
40 [](const T &t, size_t index)->const ReturnType &{
41 constexpr auto extent = std::extent<T>::value;
42 if (extent > 0 && index >= extent) {
43 throw std::range_error("Array index out of range. Received: " + std::to_string(index) + " expected < " + std::to_string(extent));
44 } else {
45 return t[index];
46 }
47 }
48 ), "[]"
49 );
50
51 m.add(fun(
52 [](const T &) {
53 constexpr auto extent = std::extent<T>::value;
54 return extent;
55 }), "size");
56 }
57
58 /// \brief Adds a copy constructor for the given type to the given Model
59 /// \param[in] type The name of the type. The copy constructor will be named "type".

Callers

nothing calls this directly

Calls 2

funFunction · 0.85
addMethod · 0.45

Tested by

no test coverage detected