Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 19 Mar 2005
Offline Last Active Jun 02 2015 09:45 AM

Topics I've Started

Testing - structure, how to?

01 March 2012 - 06:10 AM

So I've done a fair bit of hobby development, but never done anything beyond look furtively at any remotely formal testing. I 'check things work' and not much more. I've tried to do differently for my current project, partly because it's towards a dissertation and the assessment considers it, but also because the failure modes are sufficiently involved that it's a terrible idea not to.

How are tests normally structured? I wrote tests for components either beforehand or at least alongside, but I usually replaced these with functional code afterwards. So I suppose my regression testing is pretty limited, but the components are sufficiently orthogonal that I've been more-or-less able to write and debug them then leave alone. I have some Octave scripts that generate test cases for some elements. Do I just have a 'make tests' which runs those scripts to generate the test data files and swaps in an alternative main.cpp?

Also, how do I test e.g. stochastic model-fitting code? So far I've checked by eye that it looks sensible, but do I want to have some code which compares the fitted model to ground truth and checks it's within some tolerance, maybe with some sort of 'voting' system to account for the element of randomness?

C++11 variadic template beginner's problems

13 February 2012 - 06:05 PM

#include <iostream>

template <typename T>

T add(const T& a)

{ return a; }

template <typename T0, typename ... Ts>

auto add(const T0& a, const Ts& ... bs) -> decltype(a + add(bs ...))

{ return a + add(bs ...); }

int main()


    std::cout << add(1, 2, 3) << "\n";


test.cpp: In function ‘int main()’:
test.cpp:13:29: error: no matching function for call to ‘add(int, int, int)’
test.cpp:13:29: note: candidates are:
test.cpp:4:3: note: template<class T> T add(const T&)
test.cpp:8:6: note: template<class T0, class ... Ts> decltype ((a + add(add::bs ...))) add(const T0&, const Ts& ...)

Works fine for add(1, 2). What's my mistake? I realize it's probably fairly fundamental. Thanks. :-)


25 October 2011 - 11:00 AM

I have something that looks like:

[source lang="cpp"]template <typename T>struct Traits{ typedef BOOST_TYPEOF(&T::operator()) MemOpPtr; // ... boost::function_types and mpl magic ...};template <typename O, typename I>struct Traits<O (*)(I)>{ /* ... */ };// overload Atemplate <typename T> void func(const T& o){ /* uses Traits<T> */ }// overload B - binds a boost::function holding T::operator() to ptemplate <typename T> void func(const boost::shared_ptr<T>& p){ /* uses Traits<T> */ }[/source]

How can I have overload B be used when A's Traits substitution fails? I can just rename the second overload, but would prefer to keep the same syntax if possible. At the moment, I'll get errors telling me that operator() isn't a member of boost::shared_ptr. BOOST_TYPEOF (alone) doesn't give SFINAE, but I think something like enable_if< is_defined<T::operator()> > on the default Traits would suffice?


xmmintrin.h - missing semicolon?

04 February 2011 - 12:04 PM

Compiling this:
#ifndef SIMD_H
#define SIMD_H

#include <xmmintrin.h>

struct Foo {};


error C2236: unexpected 'struct' 'Foo'. Did you forget a ';'?
error C2143: syntax error : missing ';' before '{'
error C2447: '{' : missing function header (old-style formal list?)

Putting a semicolon after the include lets it compile. I'm assuming I'm missing something obvious :-)

Poisson distribution

11 January 2011 - 07:43 PM

I'm playing with a particle system. I'd like to be able to specify a rate (in particles emitted/second) for emitters, but I don't want emissions to occur at regular intervals, rather having the number of particles produced in a given second be distributed (albeit fairly tightly) about the specified mean, for a more organic look.

How can I go about doing this?