Boost.Futures


[]#include[] []<iostream>[] []// for std::cin[]
[]#include[] []<boost/assert.hpp>[]
[]#include[] []<boost/bind.hpp>[]
[]#include[] []<boost/concept_check.hpp>[] []// for ignore_unused_variable_warning[]
[]#include[] []<boost/cstdlib.hpp>[] []// for exit_success[]

[]#pragma[][] warning(push)[]
[]#pragma[][] warning(disable: 4100 4180 4355 4511 4512)[]
[]#include[] []<boost/futures.hpp>[]
[]#include[] []<boost/spirit/fusion/sequence/get.hpp>[]
[]#include[] []<boost/spirit/fusion/sequence/tuple.hpp>[]
[]#pragma[][] warning(pop)[]

[]int[] []factorial[][]([][]int[] []n[][]) {[]
[]return[] []n[][] == [][]0[][] ? [][]0[][] : ([][]n[][] == [][]1[][] ? [][]1[][] : [][]n[][] * [][]factorial[][]([][]n[][]-1[][]));[]
[]}[]

[]namespace[] []futures[][] = [][]boost[][]::[][]futures[][];[]
[]namespace[] []fusion[][] = [][]boost[][]::[][]fusion[][];[]

[]int[] []main[][]([][]int[] []argc[][], [][]char[][] *[][]argv[][][])[]
[]{[]
[]futures[][]::[][]simple_future[][]<[][]int[][]> [][]f1[][] = [][]boost[][]::[][]bind[][]([][]factorial[][], [][]4[][]);[]
[]futures[][]::[][]simple_future[][]<[][]int[][]> [][]f2[][] = [][]boost[][]::[][]bind[][]([][]factorial[][], [][]6[][]);[]
[]futures[][]::[][]simple_future[][]<[][]int[][]> [][]f3[][] = [][]boost[][]::[][]bind[][]([][]factorial[][], [][]8[][]);[]

[]typedef[] []fusion[][]::[][]tuple[][]<[][]int[][], [][]int[][], [][]int[][]> [][]result_t[][];[]
[]futures[][]::[][]future[][]<[][]result_t[][]> [][]f_and[][] = [][]f1[][] && [][]f2[][] && [][]f3[][];[]
[]result_t[] []result[][] = [][]f_and[][]();[]

[]BOOST_ASSERT[][]([]
[]fusion[][]::[][]get[][]<[][]0[][]>([][]result[][]) == [][]24[][] &&[]
[]fusion[][]::[][]get[][]<[][]1[][]>([][]result[][]) == [][]720[][] &&[]
[]fusion[][]::[][]get[][]<[][]2[][]>([][]result[][]) == [][]40320[]
[] );[]

[]std[][]::[][]cin[][].[][]ignore[][](); [][]// makes ~visitor_registry succeed...[]

[]boost[][]::[][]ignore_unused_variable_warning[][](([][]argc[][], [][]argv[][]));[]
[]return[] []boost[][]::[][]exit_success[][];[]
[]}[]