Click here to Skip to main content
16,008,490 members
Home / Discussions / ATL / WTL / STL
   

ATL / WTL / STL

 
GeneralConfused on UISetRadio() Pin
Tommy2k6-Apr-03 23:53
Tommy2k6-Apr-03 23:53 
GeneralRe: Confused on UISetRadio() Pin
Michael Dunn7-Apr-03 7:48
sitebuilderMichael Dunn7-Apr-03 7:48 
GeneralRe: Confused on UISetRadio() Pin
Tommy2k10-Apr-03 7:03
Tommy2k10-Apr-03 7:03 
GeneralRe: Confused on UISetRadio() Pin
Michael Dunn3-May-03 12:54
sitebuilderMichael Dunn3-May-03 12:54 
Generalfor_each / accumulate Pin
Chris Losinger5-Apr-03 10:03
professionalChris Losinger5-Apr-03 10:03 
GeneralRe: for_each / accumulate Pin
valikac6-Apr-03 6:47
valikac6-Apr-03 6:47 
GeneralRe: for_each / accumulate Pin
Zdeslav Vojkovic7-Apr-03 23:36
Zdeslav Vojkovic7-Apr-03 23:36 
GeneralRe: for_each / accumulate Pin
jbarton10-Apr-03 2:34
jbarton10-Apr-03 2:34 
There is a way to do this by writing a template for the functor. You can do something like:

<br />
#include <iostream><br />
#include <numeric><br />
#include <vector><br />
<br />
using namespace std;<br />
<br />
template<typename SumType, class D><br />
class MemFuncAdder<br />
{<br />
public:<br />
   typedef SumType (D::*func) () const;<br />
<br />
   MemFuncAdder( func f )<br />
      {<br />
      m_f = f;<br />
      }<br />
<br />
   SumType operator() (SumType running_sum, const D& data)<br />
      {<br />
      return (running_sum + (data.*m_f) () );<br />
      }<br />
private:<br />
   func  m_f;<br />
};<br />
<br />
class Data<br />
{<br />
   int value1;<br />
   int value2;<br />
   public:<br />
      Data( int v1, int v2) : value1(v1), value2(v2) {}<br />
<br />
      int  V1() const { return (value1); }<br />
      int  V2() const { return (value2); }<br />
<br />
      friend ostream& operator<< ( ostream &os, const Data &data)<br />
      {<br />
         os << "( " << data.value1 << ", " << data.value2 << ")";<br />
         return os;<br />
      }<br />
};<br />
<br />
int main(int argc, char* argv[])<br />
{<br />
   vector<Data>  array;<br />
<br />
   array.push_back( Data( 1,1) );<br />
   array.push_back( Data( 1,2) );<br />
   array.push_back( Data( 1,3) );<br />
   array.push_back( Data( 1,4) );<br />
   array.push_back( Data( 1,5) );<br />
<br />
   copy( array.begin(), array.end(), ostream_iterator<Data>( cout, ", " ));<br />
   cout << endl;<br />
<br />
   cout << "Result 1 = " << accumulate( array.begin(), array.end(), 0, MemFuncAdder<int,Data>(&Data::V1) ) << endl;<br />
   cout << "Result 2 = " << accumulate( array.begin(), array.end(), 0, MemFuncAdder<int,Data>(&Data::V2) ) << endl;<br />
<br />
   return 0;<br />
}<br />


Once you provide the MemFuncAdder template, you can call accumulate on multiple member functions without needing to write additional code. If you need a different operation other than addition, you could provide other templated functor classes.
GeneralCListCtrl as STL container Pin
Chris Losinger4-Apr-03 4:04
professionalChris Losinger4-Apr-03 4:04 
GeneralRe: CListCtrl as STL container Pin
Joaquín M López Muñoz4-Apr-03 4:14
Joaquín M López Muñoz4-Apr-03 4:14 
GeneralRe: CListCtrl as STL container Pin
Chris Losinger4-Apr-03 4:25
professionalChris Losinger4-Apr-03 4:25 
GeneralRe: CListCtrl as STL container Pin
Nick Parker4-Apr-03 4:38
protectorNick Parker4-Apr-03 4:38 
GeneralRe: CListCtrl as STL container Pin
Chris Losinger4-Apr-03 4:52
professionalChris Losinger4-Apr-03 4:52 
GeneralRe: CListCtrl as STL container Pin
Neville Franks12-Apr-03 12:13
Neville Franks12-Apr-03 12:13 
GeneralCustom property pages for device manager using WTL Pin
NarayanaRajaniX3-Apr-03 17:31
NarayanaRajaniX3-Apr-03 17:31 
QuestionHow to create Transparent Bitmap? Pin
jkav3-Apr-03 16:43
jkav3-Apr-03 16:43 
AnswerRe: How to create Transparent Bitmap? Pin
Ed Gadziemski7-Apr-03 4:56
professionalEd Gadziemski7-Apr-03 4:56 
Generalusing cin.getline() with string Pin
Luis E. Cuadrado3-Apr-03 2:47
Luis E. Cuadrado3-Apr-03 2:47 
GeneralRe: using cin.getline() with string Pin
valikac3-Apr-03 13:31
valikac3-Apr-03 13:31 
GeneralRe: using cin.getline() with string Pin
Luis E. Cuadrado4-Apr-03 1:55
Luis E. Cuadrado4-Apr-03 1:55 
GeneralRe: using cin.getline() with string Pin
Joaquín M López Muñoz4-Apr-03 2:33
Joaquín M López Muñoz4-Apr-03 2:33 
GeneralRe: using cin.getline() with string Pin
Luis E. Cuadrado4-Apr-03 5:34
Luis E. Cuadrado4-Apr-03 5:34 
GeneralSTL Fix Pin
Derek Lakin30-Mar-03 21:51
Derek Lakin30-Mar-03 21:51 
GeneralRe: STL Fix Pin
jhwurmbach30-Mar-03 22:28
jhwurmbach30-Mar-03 22:28 
GeneralRe: STL Fix Pin
Derek Lakin30-Mar-03 23:52
Derek Lakin30-Mar-03 23:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.