/usr/include/hphp/util/match.h is in hhvm-dev 3.11.1+dfsg-1ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | /*
+----------------------------------------------------------------------+
| HipHop for PHP |
+----------------------------------------------------------------------+
| Copyright (c) 2010-2015 Facebook, Inc. (http://www.facebook.com) |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
*/
#ifndef incl_HPHP_UTIL_MATCH_H_
#define incl_HPHP_UTIL_MATCH_H_
#include <utility>
#include <boost/variant.hpp>
namespace HPHP {
//////////////////////////////////////////////////////////////////////
/*
* This is a utility for short-hand visitors (using lambdas) with
* boost::apply_visitor.
*
* Usage e.g.:
*
* match<return_type>(
* thing,
* [&] (TypeA a) { ... },
* [&] (TypeB b) { ... }
* );
*/
//////////////////////////////////////////////////////////////////////
namespace match_detail {
template<class Ret, class... Lambdas> struct visitor;
template<class Ret, class L, class... Lambdas>
struct visitor<Ret,L,Lambdas...> : L, visitor<Ret,Lambdas...> {
using L::operator();
using visitor<Ret,Lambdas...>::operator();
visitor(L l, Lambdas&&... lambdas)
: L(l)
, visitor<Ret,Lambdas...>(std::forward<Lambdas>(lambdas)...)
{}
};
template<class Ret, class L>
struct visitor<Ret,L> : L {
typedef Ret result_type;
using L::operator();
/* implicit */ visitor(L l) : L(l) {}
};
template<class Ret> struct visitor<Ret> {
typedef Ret result_type;
visitor() {}
};
template<class Ret, class... Funcs>
visitor<Ret,Funcs...> make_visitor(Funcs&&... funcs) {
return { std::forward<Funcs>(funcs)... };
}
}
template<class Ret, class Var, class... Funcs>
Ret match(Var& v, Funcs&&... funcs) {
return boost::apply_visitor(
match_detail::make_visitor<Ret>(std::forward<Funcs>(funcs)...),
v
);
}
//////////////////////////////////////////////////////////////////////
}
#endif
|