// Copyright (C) 2017-2018 Jonathan Müller
// This file is subject to the license terms in the LICENSE file
// found in the top-level directory of this distribution.
#ifndef CPPAST_CPP_ARRAY_TYPE_HPP_INCLUDED
#define CPPAST_CPP_ARRAY_TYPE_HPP_INCLUDED
#include
#include
namespace cppast
{
/// An array of a [cppast::cpp_type]().
class cpp_array_type final : public cpp_type
{
public:
/// \returns A newly created array.
/// \notes `size` may be `nullptr`.
static std::unique_ptr build(std::unique_ptr type,
std::unique_ptr size)
{
return std::unique_ptr(
new cpp_array_type(std::move(type), std::move(size)));
}
/// \returns A reference to the value [cppast::cpp_type]().
const cpp_type& value_type() const noexcept
{
return *type_;
}
/// \returns An optional reference to the [cppast::cpp_expression]() that is the size of the
/// array. \notes An unsized array - `T[]` - does not have a size.
type_safe::optional_ref size() const noexcept
{
return type_safe::opt_cref(size_.get());
}
private:
cpp_array_type(std::unique_ptr type, std::unique_ptr size)
: type_(std::move(type)), size_(std::move(size))
{}
cpp_type_kind do_get_kind() const noexcept override
{
return cpp_type_kind::array_t;
}
std::unique_ptr type_;
std::unique_ptr size_;
};
} // namespace cppast
#endif // CPPAST_CPP_ARRAY_TYPE_HPP_INCLUDED