|
Boost : |
Subject: Re: [boost] [contract] syntax redesign
From: Lorenzo Caminiti (lorcaminiti_at_[hidden])
Date: 2011-10-25 11:35:42
On Mon, Oct 24, 2011 at 7:01 PM, lcaminiti <lorcaminiti_at_[hidden]> wrote:
> Dave Abrahams wrote:
>> No, it's still too dense because of the comments (and the redundant
>> optional "namespace tag"). Try again, please :-)
> Sure, that's easy. Let me know if this still requires more work:
For template parameters:
namespace py {
BOOST_PARAMETER_TEMPLATE_KEYWORD(ClassType)
BOOST_PARAMETER_TEMPLATE_KEYWORD(BaseList)
BOOST_PARAMETER_TEMPLATE_KEYWORD(HeldType)
BOOST_PARAMETER_TEMPLATE_KEYWORD(Copyable)
CONTRACT_CLASS(
template(
in requires(is_class<_>) ClassType,
in requires(is_sequence<_>) BaseList, default bases<>,
in class HeldType, default ClassType,
in typename Copyable, default void
)
class (class_) requires( ... ) // concepts
) {
... // declarations with class invariants, preconditions, postconditions
};
} // namespace py
typedef py::class_< py::ClassType<B>, py::Copyable<noncopyable> > c1;
typedef py::class_< D, py::HeldType< auto_ptr<D> >, py::BaseList<
bases<B> > > c2;
As you can see the syntax is exactly the same as for function
parameters (see quoted text below) with the exception of using
typename or class instead of auto for a parameter without any
requirement.
Similarly, for deduced template parameters:
namespace py {
BOOST_PARAMETER_TEMPLATE_KEYWORD(ClassType)
BOOST_PARAMETER_TEMPLATE_KEYWORD(BaseList)
BOOST_PARAMETER_TEMPLATE_KEYWORD(HeldType)
BOOST_PARAMETER_TEMPLATE_KEYWORD(Copyable)
CONTRACT_CLASS(
template(
in requires(is_class<_>) ClassType,
deduce in requires(is_base_and_derived<detail::bases_base, _>) BaseList,
default bases<>,
deduce in requires(not_< or_< is_base_and_derived<detail::bases:base, _>,
is_same<noncopyable, _> > >) HeldType, default ClassType,
deduce in requires(is_same<noncopyable, _>) Copyable, default void
)
class (class_) requires( ... ) // concepts
) {
... // declarations with class invariants, preconditions, postconditions
};
} // namespace py
typedef py::class_< B, noncoyable > d1;
typedef py::class_< D, auto_ptr<D>, bases<B> > d2;
These macros should be able to automatically generate all needed
Boost.Parameter code (template skeleton, signature, binding, and
parameter typedefs).
> #include <contract.hpp>
>
> using namespace boost;
> using namespace boost::mpl::placeholders;
> using namespace boost::python;
>
> namespace graphs {
>
> BOOST_PARAMETER_NAME(graph)
> BOOST_PARAMETER_NAME(visitor)
> BOOST_PARAMETER_NAME(root_vertex)
> BOOST_PARAMETER_NAME(index_map)
> BOOST_PARAMETER_NAME(color_map)
>
> CONTRACT_FUNCTION(
> void (depth_first_search) (
> in requires(is_incidence_and_vertex_list_graph<_>) graph,
> in auto visitor, default dfs_visitor<>(),
> in (typename graph_traits<graph_type>::vertex_descriptor)
> root_vertex, default *vertices(graph).first,
> in requires(is_integral_property_map_of_key<_, typename
> graph_traits<
> graph_type>::vertex_descriptor>) index_map,
> default get(vertex_index, graph),
> in out requires(is_property_map_of_key<_, typename graph_traits<
> graph_type>::vertex_descriptor>) color_map,
> default default_color_map(num_vertices(graph), index_map)
> )
> precondition( ... )
> postcondition( ... )
> ) {
> ...
> }
>
> } // namespace graphs
>
> namespace py {
>
> CONTRACT_FUNCTION(
> void (def) (
> in (char const*) name,
> in auto func,
> deduce in (char const*) docstring, default "",
> deduce in requires(is_keyword_expression<_>) keywords,
> default no_keywords,
> deduce in requires(not_< or_<is_convertible<_, char const*>,
> is_keyword_expression<_> > >) policies,
> default default_call_policies
> )
> precondition( ... )
> postcondition( ... )
> ) {
> ...
> }
>
> } // namespace py
>
> What do you think?
--Lorenzo
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk