Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Implicit template parameter specification

20 views
Skip to first unread message

grizlyk

unread,
Jun 28, 2016, 3:25:05 PM6/28/16
to
Concerning implicit template parameter specification.

Good day.
1. There is random taken original code

//mouse wheel
class Va_mw: public Vaction{
public:
void proceed();

Va_mw():key_timer_passed(0){}

protected:
//what mouse event to do in child
virtual
void m_event()=0;

//repeat time counter
unsigned key_timer_passed;
};

//mouse wheel up
class Te_mw_up: public Va_mw{
public:
//on hold
void m_event();
};

//mouse wheel dn
class Te_mw_dn: public Va_mw{
public:
//on hold
void m_event();
};

The code was redesigned and it was useful to apply template here. If you have questions about template parameter type definition, you can consider the folowing way of the implicit type definition

//Ta_mwe::Tevent compile time interface
template<class Tevent>
class Ia_mwe_event{
public:
//void m_event();
typedef
void
(Tevent::* f_m_event)
();

public:
Ia_mwe_event(){
f_m_event m_event= &Tevent::m_event;
}
};

//mouse wheel up
class Tevent_mw_up{
public:
//on hold
void m_event();

protected:
Ia_mwe_event<Tevent_mw_up>
anIevent;
};

//mouse wheel
template<class Tevent>
class Ta_mwe: public Vaction{
public:
void proceed();

protected:
Tevent e_mw;

protected:
Ia_mwe_event<Tevent>
anIevent;
};

2. To remove the low level type support code, C++ can be improved.

the code above is C++ "allows but does not support" low level implicit way to use the following proposed rules:

compile time interface for abstract types of data (ADT)
#//mouse wheel event
#using interface = std::ct_adt_interface;
#interface Ia_mw_event{
#public:
# void m_event();
#};
';' is mandatory here, the same as class scope

interface name can be used instead of typeless "class" keyword for template parameter declaration
interface name can be used to specialization of declared typeless "class" template parameter
#//mouse wheel
#template<Ia_mw_event Tevent>
#class Ta_mw: public Vaction{
#public:
#...

interface can not be used as run-time template (as ordinary C++ run-time interface "class" does)
because there is no the object in memory as "interface" and object of "interface type" can not be defined

abstract types of data itself has no "inheritance" mechanism of class creation of object programming
so interface can not be inherited as ordinary C++ class does
and interface can not be inherited by class syntax to avoid confusing with class specific inheritance rules

but abstract types of data itself must have a way to generic use different ADTs with the same methods in code templates
so to declare class, which is complaint an interface, the following syntax must be used
class name [: list of base class](optional) [interface: list of interfaces](optional) [{ class body }](class definition);
#//mouse wheel up
#class Tevent_mw_up
#interface: public Ia_mw_event{
#public:
#...
here class Tevent_mw_up can be used where interface Ia_mw_event does

members and types which are declared in an interface must be defined in classes which are complaint the interface
and the interface members can not be removed by class declaration

to declare interface, which is complaint the other interface, the following syntax must be used
interface name [interface: list of interfaces](optional) [{ interface body }](interface definition);
#interface Ia_mw_event2
#interface: Ia_mw_event{
#public:
# void m_event2();
#};
here interface Ia_mw_event2 can be used where interface Ia_mw_event does

interface can declare other interfaces as members by the following syntax of object definition of "interface type"
#interface Ia_mw_event3{
#public:
# Ia_mw_event a_mw_event;
#};
in classes Ia_mw_event interface type name must be replaced by class type name which are complaint the interface
here Ia_mw_event must not be used as template parameter
because all Ia_mw_event replacements are the same Ia_mw_event3 compile time interface
but template parameters used to create different compile-time interfaces by different parameters with similar compile-time interface
in other words, all compile time interface names "already generic by default"

the same example with "template" used for another purpose and the interface definition
will produce set of different compile time interfaces Ia_mw_event4<>, depends on anIa_mw_event
#template<Ia_mw_event anIa_mw_event>
#interface Ia_mw_event4{
#public:
# anIa_mw_event a_mw_event;
#};

interface can define internal interfaces as own namespace members with the same generic "interface definition"

interface can define own members by exporting member declaration from other interfaces with "using" by the following syntax
using [interface](optional) interface_name;
using interface_name::member_name;
in the case "new" interface is not the same as "used" though has the same members
the way is intended to break links between different classes with similar members by type, but logically not equal ones
interface can explicitly redeclare items inserted by "using" by ordinary rules

interface can define own scope member by the following syntax of namespace definition
namespace scope_name{
}
"interface scope" can be accessed with "::" operator like this: "interface_name::scope_name", not by "."
interface scope can define own members by exporting member declaration from other interfaces with "using" keyword
interface can explicitly redeclare items within namespace inserted by "using" by ordinary rules

class can include interfaces with "using" keyword for internal purposes
all members of the "using" interface must be declared in the class
but the class will not be complaint the "using" interface

changed interface can be added to class outside of class definition by ordinary work with interfaces
which are already declared inside class definition
(work by inherinace existed interface, by include existed interface, etc)
in general case it is prohibited to add changed interfaces to class outside of class definition

so in order to add new interfaces to class outside of class definition
in general case you must create new class but the same as existing
but to avoid the useless work with run-time properties of the existing class
there is a way to add new interfaces to class outside of class definition
by the following syntax
interface interface_name = class_name [, class_name](optional);
"interface_name" and "class_name" must be declared (but may be not defined)
"class_name" can be tested for compliant to "interface_name" in the point of both class and interface definition
the same as if "interface_name" was declared inside "class_name" definition

PS:
Complete text of the code example can be obtained here http://grizlyk1.narod.ru/cpp_new/msg02/template_interfaces_280616.pdf (only C++ code and C++ improvements rules in english)

Best regards.
0 new messages