Replace C++0x lambda with Boost Lambda Library

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
This commit is contained in:
Anders Kaseorg
2012-02-17 19:30:11 -05:00
parent 3e81d42f74
commit bd3ffb85d5
2 changed files with 18 additions and 14 deletions
+13 -11
View File
@@ -16,6 +16,8 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <boost/lambda/lambda.hpp>
#include <boost/lambda/bind.hpp>
#include <algorithm> #include <algorithm>
#include <wchar.h> #include <wchar.h>
#include <list> #include <list>
@@ -24,6 +26,7 @@
#include "terminaloverlay.h" #include "terminaloverlay.h"
using namespace boost::lambda;
using namespace Overlay; using namespace Overlay;
using std::max; using std::max;
@@ -98,8 +101,8 @@ Validity ConditionalOverlayCell::get_validity( const Framebuffer &fb, int row,
if ( (current.contents == replacement.contents) if ( (current.contents == replacement.contents)
|| (current.is_blank() && replacement.is_blank()) ) { || (current.is_blank() && replacement.is_blank()) ) {
auto it = find_if( original_contents.begin(), original_contents.end(), auto it = find_if( original_contents.begin(), original_contents.end(),
[&]( const Cell &x ) { return ( (replacement.is_blank() && x.is_blank()) (replacement.is_blank() && bind( &Cell::is_blank, _1 ))
|| (replacement.contents == x.contents) ); } ); || replacement.contents == (&_1)->*&Cell::contents );
if ( it == original_contents.end() ) { if ( it == original_contents.end() ) {
return Correct; return Correct;
} else { } else {
@@ -311,7 +314,7 @@ void TitleEngine::set_prefix( const wstring s )
void ConditionalOverlayRow::apply( Framebuffer &fb, uint64_t confirmed_epoch, bool flag ) const void ConditionalOverlayRow::apply( Framebuffer &fb, uint64_t confirmed_epoch, bool flag ) const
{ {
for_each( overlay_cells.begin(), overlay_cells.end(), [&]( const ConditionalOverlayCell &x ) { x.apply( fb, confirmed_epoch, row_num, flag ); } ); for_each( overlay_cells.begin(), overlay_cells.end(), bind( &ConditionalOverlayCell::apply, _1, var(fb), confirmed_epoch, row_num, flag ) );
} }
void PredictionEngine::apply( Framebuffer &fb ) const void PredictionEngine::apply( Framebuffer &fb ) const
@@ -321,15 +324,15 @@ void PredictionEngine::apply( Framebuffer &fb ) const
|| (display_preference == Always) ); || (display_preference == Always) );
if ( show ) { if ( show ) {
for_each( cursors.begin(), cursors.end(), [&]( const ConditionalCursorMove &x ) { x.apply( fb, confirmed_epoch ); } ); for_each( cursors.begin(), cursors.end(), bind( &ConditionalCursorMove::apply, _1, var(fb), confirmed_epoch ) );
for_each( overlays.begin(), overlays.end(), [&]( const ConditionalOverlayRow &x ){ x.apply( fb, confirmed_epoch, flagging ); } ); for_each( overlays.begin(), overlays.end(), bind( &ConditionalOverlayRow::apply, _1, var(fb), confirmed_epoch, flagging ) );
} }
} }
void PredictionEngine::kill_epoch( uint64_t epoch, const Framebuffer &fb ) void PredictionEngine::kill_epoch( uint64_t epoch, const Framebuffer &fb )
{ {
cursors.remove_if( [&]( ConditionalCursorMove &x ) { return x.tentative( epoch - 1 ); } ); cursors.remove_if( bind( &ConditionalCursorMove::tentative, _1, epoch - 1 ) );
cursors.push_back( ConditionalCursorMove( local_frame_sent + 1, cursors.push_back( ConditionalCursorMove( local_frame_sent + 1,
fb.ds.get_cursor_row(), fb.ds.get_cursor_row(),
@@ -526,16 +529,15 @@ void PredictionEngine::cull( const Framebuffer &fb )
} }
} }
cursors.remove_if( [&]( const ConditionalCursorMove &x ) { cursors.remove_if( bind( &ConditionalCursorMove::get_validity, _1, var(fb),
return (x.get_validity( fb, local_frame_sent, local_frame_acked, local_frame_late_acked,
local_frame_sent, local_frame_acked, local_frame_late_acked, now ) != Pending );
now ) != Pending); } );
} }
ConditionalOverlayRow & PredictionEngine::get_or_make_row( int row_num, int num_cols ) ConditionalOverlayRow & PredictionEngine::get_or_make_row( int row_num, int num_cols )
{ {
auto it = find_if( overlays.begin(), overlays.end(), auto it = find_if( overlays.begin(), overlays.end(),
[&]( const ConditionalOverlayRow &x ) { return x.row_num == row_num; } ); (&_1)->*&ConditionalOverlayRow::row_num == row_num );
if ( it != overlays.end() ) { if ( it != overlays.end() ) {
return *it; return *it;
+5 -3
View File
@@ -16,6 +16,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <boost/lambda/lambda.hpp>
#include <algorithm> #include <algorithm>
#include <list> #include <list>
#include <stdio.h> #include <stdio.h>
@@ -23,6 +24,7 @@
#include "transportsender.h" #include "transportsender.h"
#include "transportfragment.h" #include "transportfragment.h"
using namespace boost::lambda;
using namespace Network; using namespace Network;
using namespace std; using namespace std;
@@ -280,8 +282,8 @@ void TransportSender<MyState>::process_acknowledgment_through( uint64_t ack_num
/* Ignore ack if we have culled the state it's acknowledging */ /* Ignore ack if we have culled the state it's acknowledging */
if ( sent_states.end() != find_if( sent_states.begin(), sent_states.end(), if ( sent_states.end() != find_if( sent_states.begin(), sent_states.end(),
[&]( const TimestampedState<MyState> &x ) { return x.num == ack_num; } ) ) { (&_1)->*&TimestampedState<MyState>::num == ack_num ) ) {
sent_states.remove_if( [&]( const TimestampedState<MyState> &x ) { return x.num < ack_num; } ); sent_states.remove_if( (&_1)->*&TimestampedState<MyState>::num < ack_num );
} }
assert( !sent_states.empty() ); assert( !sent_states.empty() );
@@ -315,7 +317,7 @@ uint64_t TransportSender<MyState>::get_late_ack( uint64_t now )
} }
} }
ack_history.remove_if( [&]( const pair<uint64_t, uint64_t> &x ) { return x.first < newest_echo_ack; } ); ack_history.remove_if( (&_1)->*&pair<uint64_t, uint64_t>::first < newest_echo_ack );
return newest_echo_ack; return newest_echo_ack;
} }