Skip to content

Instantly share code, notes, and snippets.

@jefftrull
Last active July 23, 2019 21:08
Show Gist options
  • Save jefftrull/123021f5a0b06be8d0ec5a96e753551d to your computer and use it in GitHub Desktop.
Save jefftrull/123021f5a0b06be8d0ec5a96e753551d to your computer and use it in GitHub Desktop.

Testing C++ tangling from org-mode

Introduction

First Slide

This is a test of exporting with code from org-mode

some required setup:

(org-babel-do-load-languages
  'org-babel-load-languages '((C . t)))

Code

All-in-One Example

using namespace std;
vector<int> foo{1, 2, 3};
copy(foo.begin(), foo.end(), ostream_iterator<int>(cout, " "));

You can go into the above code and type C-c C-c to have it compiled and the results inserted above this line.

Code Fragment with Scaffold

Sometimes you need more than just a few includes or flags etc. to properly support your code block, but you don’t want to uglify your slides with the boilerplate. In that case we can define a hidden (unexported) scaffold code block that incorporates the one we display.

auto [s, i] = make_tuple("foo", 42);

The unexported scaffold would be visible below except that we used :exports none

(Note “noweb”, which enables including fragments via <<>>)

Code with Tables

This is pretty fun. You can put an inline table and supply it to some code:

NameYears at C++Now
Jeff10
Marshall12
Michael10
Ben4

Code with Tables

// sort by years
sort(begin(data), end(data),
     [](auto const& a, auto const& b)
     {
         return get<1>(a) < get<1>(b);
     }
);

for (auto const & nm_age: data)
{
     cout << get<0>(nm_age) << ": " << get<1>(nm_age) << "\n";
}

Code with Tables

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment