On 2007-02-01, Roland Levillain <roland(a)lrde.epita.fr> wrote:
> * stc/scoop.hh: Replace every occurrence of `where' (as a template
> parameter) with `location', to comply with the upcoming C++0x
> standard.
>
Do you mean that `where' is going to be a keyword in C++0x?
--
SIGOURE Benoit aka Tsuna (SUSv3 compliant)
_____ "On a long enough timeline, the survival rate
/EPITA\ Promo 2008.CSI/ACU/YAKA for everyone drops to zero" -- Jack.
2007-02-05 Thierry GERAUD <theo(a)tegucigalpa.lrde.epita.fr>
Add a README and a "SCOOP 1+" translation in doc/tiny.
* doc/tiny/a_la_scoop_1_plus: New.
* doc/tiny/README: New.
* doc/tiny/local/scoop.hh (Concept): Rename as...
(concept_): ...this.
(stc_equip_namespace): Add "vtypes< stc::any<E> >" so
that we can have SCOOP 1 with SCOOP 2 tools.
(stc_deferred): New.
* doc/tiny/a_la_scoop_2/main.cc: Update.
* doc/tiny/a_la_scoop_2/desugar.cc: Update.
* doc/tiny/more_scoop_2/main.cc: Update.
(reference): New.
* doc/tiny/design/main.cc (is_valid): Fix sig.
Index: doc/tiny/a_la_scoop_2/main.cc
===================================================================
--- doc/tiny/a_la_scoop_2/main.cc (revision 735)
+++ doc/tiny/a_la_scoop_2/main.cc (working copy)
@@ -48,7 +48,7 @@
// Iterator
template <typename Exact>
- struct Iterator : public Concept<Exact>,
+ struct Iterator : public concept_<Exact>,
public automatic::impl<Iterator, Exact>
{
stc_typename(value);
Index: doc/tiny/a_la_scoop_2/desugar.cc
===================================================================
--- doc/tiny/a_la_scoop_2/desugar.cc (revision 735)
+++ doc/tiny/a_la_scoop_2/desugar.cc (working copy)
@@ -48,7 +48,7 @@
// Iterator
template <typename Exact>
- struct Iterator : public Concept<Exact>,
+ struct Iterator : public concept_<Exact>,
public automatic::impl<Iterator, Exact>
{
stc_typename(value);
Index: doc/tiny/a_la_scoop_1_plus/gpp
===================================================================
--- doc/tiny/a_la_scoop_1_plus/gpp (revision 0)
+++ doc/tiny/a_la_scoop_1_plus/gpp (revision 0)
@@ -0,0 +1 @@
+g++ -Wall -ansi -pedantic -I../../../ -I../../../../metalic $1
Property changes on: doc/tiny/a_la_scoop_1_plus/gpp
___________________________________________________________________
Name: svn:executable
+ *
Index: doc/tiny/a_la_scoop_1_plus/main.cc
===================================================================
--- doc/tiny/a_la_scoop_1_plus/main.cc (revision 0)
+++ doc/tiny/a_la_scoop_1_plus/main.cc (revision 0)
@@ -0,0 +1,139 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory.
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+
+/* \file doc/tiny/a_la_scoop_1_plus/main.cc
+
+ \brief Tiny sample use of FIXME: SCOOP 1. */
+
+
+#include "../local/scoop.hh"
+
+
+stc_equip_namespace(abc);
+
+
+
+namespace abc
+{
+
+ // List of associated types.
+ stc_decl_associated_type(value);
+
+
+ // Iterator
+
+# define super stc::any<Exact>
+ // -----------------
+ // ^
+ // |
+# define current Iterator<Exact>
+ // -----------------
+
+# define templ template <typename Exact>
+# define classname Iterator
+
+ stc_Header;
+
+ typedef stc::abstract value; // stc::abstract is a feature of SCOOP 2.
+
+ stc_End;
+
+ template <typename Exact>
+ struct Iterator : public stc::any<Exact>
+ {
+ stc_typename(value);
+ void next() { this->exact().impl_next(); }
+ bool is_valid() const { return this->exact().impl_is_valid(); }
+ void set(const value& v) { this->exact().impl_set(v); }
+ };
+
+# include "../local/undefs.hh"
+
+
+
+ // array_iterator
+
+# define current array_iterator<T>
+ // -------------------
+
+# define templ template <typename T>
+# define classname array_iterator
+
+# define super Iterator< current >
+
+
+ stc_Header;
+
+ typedef stc::final<T> value; // stc::final is a feature of SCOOP 2.
+
+ stc_End;
+
+
+ template <typename T>
+ class array_iterator : public super
+ {
+ public:
+
+ stc_using(value);
+ void impl_next() { i_ = i_ + 1; }
+ bool impl_is_valid() const { return i_ >= 0 and i_ < n_; }
+ void impl_set(const value& v) { v_ = v; }
+
+ array_iterator(int n) : i_(0), n_(n) {}
+ protected:
+ int i_, n_;
+ value v_;
+ };
+
+# include "../local/undefs.hh"
+
+
+
+ // algo
+
+ template <typename I>
+ void algo(Iterator<I>& iter, typename I::value val)
+ {
+ if (iter.is_valid())
+ {
+ iter.set(val);
+ iter.next();
+ }
+ }
+
+
+} // abc
+
+
+int main()
+{
+ abc::array_iterator<int> i(7);
+ int val = 51;
+
+ abc::algo(i, val);
+}
Index: doc/tiny/more_scoop_2/main.cc
===================================================================
--- doc/tiny/more_scoop_2/main.cc (revision 735)
+++ doc/tiny/more_scoop_2/main.cc (working copy)
@@ -43,6 +43,7 @@
// List of associated types.
stc_decl_associated_type(value);
+ stc_decl_associated_type(reference);
stc_decl_associated_type(forward);
stc_decl_associated_type(backward);
@@ -54,7 +55,7 @@
// Iterator
template <typename Exact>
- struct Iterator : public Concept<Exact>,
+ struct Iterator : public concept_<Exact>,
public automatic::impl<Iterator, Exact>
{
stc_typename(value);
@@ -120,7 +121,7 @@
# define super top<E>
- // -------
+ // --------
// ^
// |
# define current iterator_base<E>
@@ -134,6 +135,7 @@
typedef stc::is<Iterator> category;
typedef stc::abstract value;
+ typedef stc::final< stc_deferred(value) & > reference;
stc_End;
Index: doc/tiny/design/main.cc
===================================================================
--- doc/tiny/design/main.cc (revision 735)
+++ doc/tiny/design/main.cc (working copy)
@@ -38,7 +38,7 @@
{
value : type
next : () -> void
- is_valid : const bool
+ is_valid : const () -> bool
set : (v : value const&) -> void
}
Index: doc/tiny/local/scoop.hh
===================================================================
--- doc/tiny/local/scoop.hh (revision 735)
+++ doc/tiny/local/scoop.hh (working copy)
@@ -903,13 +903,24 @@
\
\
\
+ /* stc::any vtypes in equipped namespace; code required for SCOOP 1 */ \
+ \
+ template <typename E> \
+ struct vtypes< stc::any<E> > \
+ { \
+ typedef mlc::none super_type; \
+ typedef stc::final<E> exact_type; \
+ }; \
+ \
+ \
+ \
/* concept class */ \
\
template <typename E> \
- struct Concept : public virtual stc::any<E> \
+ struct concept_ : public virtual stc::any<E> \
{ \
protected: \
- Concept() {} \
+ concept_() {} \
}; \
\
\
@@ -1031,6 +1042,12 @@
# define stc_using(Type) typedef typename super::Type Type
+# define stc_deferred(Type) \
+ typename deferred_vtype< typename deferred_vtype< current, \
+ typedef_::exact_type >::ret, \
+ typedef_::Type >::ret
+
+
// For impl classes.
# define stc_lookup(Type) typedef typename vtype< stc_type(current, exact_type), typedef_::Type>::ret Type
@@ -1050,6 +1067,8 @@
{ \
typedef super super_type \
+
+
# define stc_End }
Index: doc/tiny/README
===================================================================
--- doc/tiny/README (revision 0)
+++ doc/tiny/README (revision 0)
@@ -0,0 +1,158 @@
+ -*- outline -*-
+
+
+
+* Introduction.
+
+FIXME: ...
+
+
+
+* Contents.
+
+
+** design/
+
+Presents the sample program in a pseudo language.
+
+It defines Iterator as a record type with value (type), next,
+is_valid, set (three methods). The class array_iterator[T] is an
+implementation of an Iterator.
+
+
+** classical/
+
+Classical object-oriented C++ with abstract class and inheritance.
+The use of "void*" maps a generalization of all value types and allows
+to manually implement a covariant behavior of the "set" method.
+
+
+** cpp_with_virtual_types/
+
+Rewriting of the "classical" example but in an extension of the C++
+language with virtual types. This code does not compile! Yet it
+expresses an syntactically elegant solution to the covariance issue.
+
+
+** a_la_scoop_1/
+
+SCOOP 1 aims at writing C++ class hierarchies in a static way
+(with methods and typedefs dispatching at compile-time).
+
+Same as "cpp_with_virtual_types" but conforming to the 2003 ISO/ANSI
+C++. The "virtual" keyword has disappeared so polymorphic methods
+now are fast at run-time and the use of covariance is statically
+solved and checked.
+
+To break recursion that appears in types definitions (*), an auxiliary
+structure (vtypes) is introduced. This structure shall map the
+inheritance tree of the targeted classes so that we also get
+inheritance for virtual types.
+
+For instance, if B derives from A, we should have vtypes<B> deriving
+from vtypes<A>.
+
+(*) Precisely the following code cannot compile:
+ struct Iterator { typedef typename iter::value_ value; };
+ struct iter : Iterator { typedef int value_; };
+ because "Iterator" needs to be compiled before "iter" so
+ the definition of "value_" is unaccessible.
+
+
+** a_la_scoop_1_plus/
+
+Almost like the previous example but with the material offered to
+design with SCOOP 2.
+
+The main difference is that the "vtypes" definitions do not need
+anymore to replicate class inheritance. When B derives from A,
+vtypes<B> is no more required to derive from vtypes<A>. Yet the
+expected properties of virtual type inheritance and lookup are
+verified.
+
+Extra features are also provided:
+- "stc::abstract" to declare a typedef and get an error at
+ compile-time when a concrete subclass misses to give its definition;
+- "stc::final" to ensure that a typedef is not overridden in a
+ subclass;
+- "delegatee_type" to offer delegation;
+- furthermore typedef definitions based on deferred ones are now
+ possible (*).
+
+For instance, we can have:
+
+ stc_Header;
+ typedef stc::abstract value;
+ typedef stc::final< stc_deferred(value) & > reference;
+ stc_End;
+
+
+** a_la_scoop_2/
+
+SCOOP 2 aims both at writing C++ class hierarchies in a static way
+(just like SCOOP 1) and at decoupling concepts, models, and
+some automatic implementation when delegation is involved.
+
+In this sample code the "Iterator" concept (deriving from "concept_")
+is defined apart from the "array_iterator" class (deriving from
+"top"). An intermediate (non-client) meta-code looks up for the
+category of the implementation class so that it is plugged to the
+appropriate concept.
+
+What we can expect from this kind of design is better illustrated in
+the "more_scoop_2/" directory.
+
+
+** more_scoop_2/
+
+A more elaborate example than the previous one.
+
+FIXME: Give some explanations.
+
+
+** local/
+
+Material to equip a namespace with SCOOP 2 facilities and to program
+with the SCOOP 2 paradigm.
+
+
+** generic_programming/
+
+Dual code than the "classical" object-oriented C++ example. Iterator
+only appears in documentation and there is no explicit dependency
+between this concept and the "array_iterator" model.
+
+
+** cpp_with_concepts/
+
+The example is here rewritten in C++0x according to the proposal n2081
+from the evolution working group of the C++ Standard committee (*).
+"Iterator" is then translated into a concept.
+
+(*) www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2081.pdf
+
+
+
+* Recap.
+
+ Iterator array_iterator[T]
+ ------------------------- ------------------------
+
+design/ type implementation class
+(pseudo-code)
+
+classical/ abstract class derived class
+
+cpp_with_virtual_types/ abstract class derived class
+(this is not C++)
+
+generic_programming/ documentation stand-alone class
+
+a_la_scoop_1/ abstract class derived class
+(static) super is Any<Exact>
+
+a_la_scoop_2/ concept-like "stand-alone"-like class
+(static) super is concept_<Exact> super is top<Exact>
+
+cpp_with_concepts/ concept stand-alone class
+(future C++)
2007-02-01 Thierry GERAUD <theo(a)tegucigalpa.lrde.epita.fr>
Add a tiny example to stress differences between paradigms.
* stc/doc/tiny/: New.
* stc/scoop.hh (stc_scoop_equipment_for_namespace): Rename
SCOOPED_NAMESPACE::internal as SCOOPED_NAMESPACE::stc_vtype_internal.