A macro in computer science is a rule or pattern that specifies how a certain input sequence (often a sequence of characters) should be mapped to a replacement output sequence (also often a sequence of characters) according to a defined procedure. Do not use this tag for questions regarding ...
3
votes
1answer
17 views
Scale-able API development with macro definitions
In a couple of months I'll be part of a large(ish) project, and there's good chances my team will be a lot bigger, with at least 2 programmers (probably 3) and some 3-5, or more, consumers of the API ...
3
votes
1answer
45 views
in-nest-sequence: sequence generator in Racket
in-nest-sequence is a sequence generator that takes a function and an initial value, and the return value of invoking the function on the current value is used as ...
6
votes
1answer
59 views
Const by default
Being a C++ developer, but also having been influenced by functional languages, I strongly believe that const should be the default for the vast majority of all ...
2
votes
2answers
53 views
C++ Minimalistic Unit Testing Library
I was looking for a unit testing library for C++, and I found many. Unfortunately, I decided I didn't want to use any of them. I decided to make my own.
This is the result. I made heavy use of the ...
3
votes
0answers
63 views
Unit test macro
I have written a couple of macros (? and ??) for performing unit tests, but I'm having some difficulty with modifying it, so I ...
4
votes
1answer
81 views
Generic vector implementation in C using macros
I while ago I experimented with macros in C and came up with the idea of implementing a generic vector library using macros.
This code uses the non standard typeof ...
5
votes
0answers
65 views
Suggesting “safe enum” class for ISO C
There are quite some questions and answers about how to make enum really type-safe and I didn't find a solution that ensures both type safety and valid values. So I ...
1
vote
0answers
36 views
Creating class method using macro to accept Visitator for each of their fields
I had a lot of classes that used a macro with listed fields. The macro was used to serialization, more like MSGPACK_DEFINE. I need a substitution of this mechanism, ...
7
votes
1answer
116 views
Validation macro
I would like a review of a Scala validation library I am writing. For now we can focus on the regular expression component.
The usage is described in RegexExample.scala
There is an outline of the ...
6
votes
3answers
196 views
Macro enabling Python style 'with' in C++
I am developing a simple macro that enables Python style 'with' in C++.
I have shamelessly prefixed the macro name with BOOST_ - primarily because there's a ...
9
votes
0answers
149 views
Macro to build type declaration
These are some macros to help build a traits class (for the parser/printer classes I am building).
Traits.h
...
6
votes
0answers
88 views
Autotools detect C++ language standard support
I have been updating my build tools to optionally use autotools (autoconfig/automake/libtool etc.).
As part of this change I have written a couple of M4 macros. This not being something I have done ...
5
votes
1answer
38 views
Autotools detect YAML library
I have been updating my build tools to optionally use autotools (autoconfig/automake/libtool etc.).
As part of this change I have written a couple of M4 macros. This not being something I have done ...
3
votes
1answer
28 views
Autotools pull in standard build system
I have been updating my build tools to optionally us autotools (autoconfig/automake/libtool etc.).
As part of this change I have written a couple of M4 macros. This not being something I have done ...
2
votes
3answers
230 views
Use of macros to aid visual parsing of SFINAE template metaprogramming
I've recently been introduced to SFINAE to solve the problem of unwanted promotion precedence.
i.e. I was hoping to catch integer types with Foo::Foo(long) and ...
3
votes
1answer
256 views
Error-handling #ifdefs for AFNetworking requests
I am using AFNetworking 1.4.3 to send and receive network messages in iOS. My application works slightly differently in DEBUG and RELEASE mode, so I need to use ...
4
votes
2answers
122 views
Efficient mechanism to generate operator overload functions
I'm attempting to tidy up a C++ framework (PyCXX).
One particular file contains ~400 lines of operator overload functions, which I've managed to reduce to the following:
...
11
votes
1answer
133 views
Lua bindings for FTGL (FreeType font rendering in OpenGL)
I wrote some Lua bindings for FTGL's C API. This works well enough, but I ended up with lots of macros, one for each Lua function signature. For example, LUD_NUMBER_NUMBER_TO_NUMBER creates a Lua ...
6
votes
2answers
1k views
A tuple unpacking macro that approximates Python elegance
Motivation
Although I love coding in C++, I sometimes yearn for the syntactic sugar of Python. C++11 has somewhat eased the pain by such beautiful analogies like this:
...
1
vote
1answer
62 views
11
votes
3answers
1k views
4
votes
3answers
221 views
Penney Game - mapping macros to strings
The SPOJ problem:
Given a 40 character string representing outcomes of 40 coin tosses,
find the frequency destribution of all the possible outcome triplets.
So, for string like : HHHH....40 Hs ...
12
votes
2answers
703 views
Template vector struct in C11
This one review will be a little bit tricky: I was trying to implement a template Vector struct in C11. Of course, templates don't really exist in C11, so I used a ...
8
votes
2answers
1k views
Macro that interchanges 2 arguments
Define a macro swap(t, x, y) that interchanges two arguments of type t.(Block structure will help.)
The ideea is that a ...
6
votes
1answer
3k views
Variadic macro enum class “reflection” in C++11
I recently had the need of "reflecting" multiple enum class constructs in order to get their elements' names as std::string ...
4
votes
2answers
114 views
Macros to detect UTF-8
I'm working on a program that handles UTF-8 characters. I've made the following macros to detect UTF-8. I've tested them with a few thousand words and they seem to work.
I'll add another one to do ...
4
votes
1answer
346 views
AppleScript to close running processes
I've been trying to emulate MS Windows behavior on my OS X and close processes that do not have a window.
What I'd really like to do is "quit" the process on clicking the red "x" button. Instead, ...
2
votes
0answers
75 views
`multiple-value-call` in Scheme
Common Lisp has a "special operator" called multiple-value-call, which does something similar to Scheme's call-with-values but ...
6
votes
1answer
160 views
C++: Generating similar methods with macros
I am currently working on a project that involves Lua. For convenience, I created a wrapper class for the Lua state structure. However, I also added some methods for getting globals and table fields. ...
2
votes
2answers
488 views
C try/catch macros
I've created simple try/catch macros that now I'd like to promote to wider use in my projects.
I would have really liked to be able to do without global variables but I have not found any way to do ...
4
votes
2answers
586 views
A defined macro to copy selected values of std::vector to an array using std::copy
Thought I share this piece of code to the world. But be aware, I am not sure if this piece of code is safe and efficient. Feel free to improve it or give some feedback and suggestions.
...
2
votes
1answer
330 views
Simplify complex hash-table manipulations in Common Lisp
I'm trying to write a simple triplestore in Common Lisp that will store triples in the form subject-predicate-object. The code is inspired by the book "Programming the Semantic Web".
...
4
votes
1answer
2k views
Qt foreach-like alternative to iterate over value AND key of an associative container
The Qt documentation recommend an iterator-based solution to iterate over an associative container like QMap and QHash, and I always wondered if there really isn't a (nice) solution using a ...
1
vote
2answers
156 views
2
votes
2answers
2k views
Objective-C debug macros
I'm looking for a review of my macros. I have these in the project pre-compile header. I tent to copy them into all my new projects as well, unless its a very simple project.
...
6
votes
2answers
1k views
Solving the problem of using directives in a header file with a macro. Is this stupid?
I am writing some library code that is mostly templates and so is all contained in header files. I know that placing a using declaration in a header will pollute all the files that include it, but I'm ...
11
votes
5answers
2k views
8
votes
3answers
5k views
Generic C++ exception catch handler macro
I have this set of legacy C++ projects with a large number of public functions. At the start, none of those publicly exposed functions had try..catch insulation ...
3
votes
2answers
110 views
Keys in mode maps
I noticed a pattern in some elisp modes I was putting together:
(let ((map (make-sparse-keymap)))
(define-key map KEY 'FN)
...
(setq FOO map))
so I wrote ...
4
votes
1answer
173 views
Is this a good way to implement let-with?
I've implemented a let-with macro that takes an association list, keyed by symbols, that enables code to bind their corresponding values to local variables.
It's ...
8
votes
5answers
691 views
Resolving a link - follow-up
Similar piece of code to that I recently posted as:
Resolving a link
I have another piece of code which cannot be as easily extracted out into a method:
...