Re: [O] evaluate cpp snippet in org babel with default includes and customized entry point

2017-09-16 Thread Thierry Banel
On 16/09/2017 11:14, Amos Bird wrote: Hmm, is it possible to customize babel's c++ backend to achieve this? You mean, hiding the call to twoSum() somewhere? I am not aware of any basic way to achieve that. I may also want a evaluation that submits the code to online judge and returns the

Re: [O] evaluate cpp snippet in org babel with default includes and customized entry point

2017-09-16 Thread Amos Bird
#+OPTIONS: latex:t toc:nil H:3 Hmm, is it possible to customize babel's c++ backend to achieve this? I may also want a evaluation that submits the code to online judge and returns the result. Thierry Banel writes: > You still need to explicitly call twoSum(), and that

Re: [O] evaluate cpp snippet in org babel with default includes and customized entry point

2017-09-16 Thread Thierry Banel
You still need to explicitly call twoSum(), and that cannot be hidden. On 16/09/2017 10:58, Amos Bird wrote: Ok, i get the idea. So how can I customized the default code expansion so that it can directly evaluate this

Re: [O] evaluate cpp snippet in org babel with default includes and customized entry point

2017-09-16 Thread Thierry Banel
You may further hide the includes with a property drawer. An additional benefit is that those includes are shared among all babels under the same section. * Example :PROPERTIES: :includes: :END: #+BEGIN_SRC C++ std::cout<<"hello"; #+END_SRC #+RESULTS: : hello On 16/09/2017

Re: [O] evaluate cpp snippet in org babel with default includes and customized entry point

2017-09-16 Thread Amos Bird
#+OPTIONS: latex:t toc:nil H:3 Ok, i get the idea. So how can I customized the default code expansion so that it can directly evaluate this #+BEGIN_SRC cpp class Solution { public: vector twoSum(vector& nums, int target) { } }; #+END_SRC

Re: [O] evaluate cpp snippet in org babel with default includes and customized entry point

2017-09-16 Thread Thierry Banel
You may use the :includes header parameter. Also, you may omit the main() function. In this case, all your code will become the body of a default main function. Type C-c C-v v on the following example to understand what is happening. #+BEGIN_SRC C++ :includes std::cout<<"hello";

Re: [O] evaluate cpp snippet in org babel with default includes and customized entry point

2017-09-16 Thread Thierry Banel
Another starting point without hard-coding inputs: #+name: NUMS | 2 | | 7 | | 11 | | 15 | #+BEGIN_SRC C++ :flags -std=c++11 :var target=9 :var inputnums=NUMS #include #include using namespace std; class Solution { public: vector twoSum(vector& nums, int target) { vector result;

Re: [O] evaluate cpp snippet in org babel with default includes and customized entry point

2017-09-16 Thread Amos Bird
#+OPTIONS: latex:t toc:nil H:3 Thanks Thierry, But I'd like to hide all those includes and the main function. I'm not sure if it's possible. Thierry Banel writes: > A starting point could be as follows. > Type C-c C-c to evaluate. > Type C-c C-v v to expand the source.

Re: [O] evaluate cpp snippet in org babel with default includes and customized entry point

2017-09-16 Thread Thierry Banel
A starting point could be as follows. Type C-c C-c to evaluate. Type C-c C-v v to expand the source. #+BEGIN_SRC C++ :flags -std=c++11 #include #include using namespace std; class Solution { public: vector twoSum(vector& nums, int target) { vector result; result.push_back(0);

[O] evaluate cpp snippet in org babel with default includes and customized entry point

2017-09-16 Thread Amos Bird
#+OPTIONS: latex:t toc:nil H:3 Hi I'd like to write a blog about leetcode solutions in c++. How can I evaluate those c++ code snippet using org babel? * Array ** Two Sum Given an array of integers, return indices of the two numbers such that they add up to a specific target. You may assume