Boost logo

Boost :

From: Andy Little (andy_at_[hidden])
Date: 2004-02-07 08:13:58


Hi,
        Attached is a demo of generic operators. (tested on VC7.1 , gcc3.2)

Can be parameterised on the operator itself
Optional Concept checking for exact argument types (identifying.. so
eliminating unnecessary implicit conversions)
Can be specialised for UDTs.... giving standardised format

regards
Andy Little

user:

 meta::operator_plus<
        lhs,rhs,check_exact_funda_args
>::return_type plus_ret1=
    meta::operator_plus<
        lhs,rhs,check_exact_funda_args
>()(x,y);
    std::cout << "lhs + rhs = " << plus_ret1 <<'\n';

templateable...

 meta::binary_operation<
        lhs,std::divides,rhs,check_exact_funda_args
>::return_type div_ret=
    meta::binary_operation<
        lhs,std::divides,rhs,check_exact_funda_args
>()(x,y);
    std::cout << "lhs / rhs = " << div_ret <<'\n';

begin 666 generic_operators.zip
M4$L#!!0````(`"-F1S %C)M+Q D``,4O```:````='EP97-?<')O;6]T:6]N
M7W1R86ET<RYH<'#-&OUOVS;V]P'['QY:8$ZNJ9ND+0YSFA195VP%FB9HO!T.
MQ4&@I6>;5XG42"H^-^O_?GR49%&R9#NI`E0(6IGB^_XB^?CL&<!4R01^D5(;
M2.VK-%R*P"C&C1[.TQ3FR")4,.4Q`CSUGQ]_^/$'PK#W9A_>R'2I^&QNX#S&
MSQJ7\%NFC+R12S@^/#P<PA6JA&MMD8.1$-KI!Y!I/,A1)#+B4SNB,8Z!B0_at_B
MKHWBD\P_at_F#G7H.74+)A"L.\SQ83!B-B]X9%]H1DYGG#%AK""A @L39$I#5P`
MLZCM=XYZ".,FSA)7CN81LQ#Z$2RXF<O,`/XO5:@U2 4\26-N:5I 8L/R3.S2
M1$L2PICQ!%C!C164&TLGXX9->,S-$J86!1-+2#.52HW#0H?GX6<A%S%&LP2%
MT2,W^(N%^/+DB2-_at_Y@CO63*)&+SG$\74LA)?RP1!&Z8,%S.P0Y9[HN,4YS 1
MTTB8&5D7Y!3,,D4]J"P.N<5/8"X7>(/JP%&LPSE4$XSEPL*A01%I$G&"D$B%
M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[0
M9J*B,Z%V]][W$RK=VXRE-XHQMN'#?1RP>T0[!*ULN@":NP%9H")FQ\JUY]E#
M'AUN*[(JU+L[F)Q]<5X-8K+<=](M_A^R'E/O^%_B+9*:8=)[`IY=@3?2]9F&
MKP_#-PEK)UC/R7A^*<Y@/']*]N^(W7#K.3'/+L.;Z<Z?GMT:_)U^+B_^`5!+
M`0(H`!0````(`"-F1S %C)M+Q D``,4O```:``````````$`( ````````!T
M>7!E<U]P<F]M;W1I;VY?=')A:71S+FAP<%!+`0(H`!0````(`&]F1S"7-]UG
M# (``&D%```,``````````$`( ```/P)``!A<F=U;65N="YH<'!02P$"* `4
M````" !O9D<P8I9[CK$!``"B! ``# `````````!`" ````R# ``8V]N<W1A
M;G0N:'!P4$L!`B@`% ````@`;V9',$;>O!NB!P``.B<``!4``````````0`@
M````#0X``&=E;F5R:6-?;W!E<F%T;W)S+FAP<%!+`0(H`!0````(`(]F1S [
M.HR]H ,``#(-```(``````````$`( ```.(5``!M86EN+F-P<%!+!08`````
.!0`%`#4!``"H&0``````
`
end


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk