Skip to content

Instantly share code, notes, and snippets.

std::vector<Object> dst_objs;
// transform an iterator into a moveable one
auto it = std::make_move_iterator(src_objs.begin()),
end = std::make_move_iterator(src_objs.end());
std::copy_if(it, end, std::back_inserter(dst_objs),
[](const Object& cur) { return cur.type() == Type::TYPE1; });
std::vector<Object> dst_objs;
for(auto&& cur : src_objs) {
// filter all TYPE1 messages
if (cur.type() == Type::TYPE1)
dst_objs.push_back(std::move(cur));
}
// comparator
auto comp = [](const Object& lhs, const Object &rhs) {
return lhs.type() < rhs.type() ||
(lhs.type() == rhs.type() && std::strcmp(lhs.msg(), rhs.msg()) < 0);
};
std::sort(src_objs.begin(), src_objs.end(), comp);
enum class Type { TYPE1, TYPE2, TYPE3 };
class Object {
using LiteralPtr = std::unique_ptr<const char[]>;
Type m_type;
LiteralPtr m_msg;
static LiteralPtr make_str_copy(const char* str) {
// Given any type, return unsigned int instead
template <typename T>
struct to_uint_traits { typedef unsigned int type; };
template <typename... Args>
int enqueue_kernel( std::function<void (Args... )> block,
typename to_uint_traits<Args>::type... sizes )
{
// print sizes
for (auto size : {sizes...})
int enqueue_kernel (
queue_t queue,
kernel_enqueue_flags_t flags,
const ndrange_t ndrange,
void (^block)(local void *, ...),
uint size0, ...)
int enqueue_kernel (
queue_t queue,
kernel_enqueue_flags_t flags,
int enqueue_kernel (
queue_t queue,
kernel_enqueue_flags_t flags,
const ndrange_t ndrange,
void (^block)(void))
int enqueue_kernel (
queue_t queue,
kernel_enqueue_flags_t flags,
const ndrange_t ndrange,
set(FlexTemplFile ${CMAKE_SOURCE_DIR}/lexer.ll.in)
set(FlexSpecFile ${TMP_DIR}/lexer.ll)
# Initialize the file opcodes.ll.cpp with the X-Macro code which extracts lexing rules
# from the opcodes contained in the opcodes.def file (file is generated when cmake is executred)
file(WRITE ${TMP_DIR}/opcodes.ll.cpp
"\#define OPERATOR(NAME, ...) NAME { return OP_##NAME; }\n"
"\#include \"opcodes.def\"\n")
# A rule which runs the preprocessor of the opcodes.ll.cpp file and gives the content to a
cmake_minimum_required (VERSION 2.8)
project (blog)
# CHECKs if a C++11 compiler is available
if(CMAKE_COMPILER_IS_GNUCXX)
execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
if (GCC_VERSION VERSION_GREATER 4.7 OR GCC_VERSION VERSION_EQUAL 4.7)
message(STATUS "C++11 activated.")
add_definitions("-std=c++11")
else ()
%code requires
{
#include <string>
}
%{
#include <iostream>
void yyerror(const char *s)
{