Boost logo

Boost :

From: nbecker_at_[hidden]
Date: 2001-08-30 08:28:16


I'm getting a compile error with gcc-3.0.1 with some of my code that
uses boost::random. I can't understand the problem. Would someone be
so kind as to tell me if my code is wrong, or whether I should report
this to gcc-bugs?

The problem is with the "maybe_random" class:

SigGen2.H
---------------------
#ifndef SigGen_H
#define SigGen_H

// $Id: SigGen.H,v 1.7 2001/08/15 11:47:59 nbecker Exp $

//#include "pnseq_generator.H"
#include <boost/random.hpp>
#include <algorithm>
#include <vector>
using std::vector;

template<typename iter, typename gen>
void generate_ref (iter start, iter end, gen g) {
#if (__GNUC__ > 2)
  std::generate<iter, gen&> (start, end, g);
#else
  generate<iter, gen&> (start, end, g);
#endif
}

template<typename Rng>
class maybe_random {
  typedef typename Rng::result_type result_type;
public:
  maybe_random (bool _isRandom, result_type _fixedVal, Rng& _rng) :
    isRandom (_isRandom), fixedVal (_fixedVal), rng (_rng) {}

  result_type operator()() {
    return isRandom ? rng() : fixedVal;
  }
private:
  bool isRandom;
  result_type fixedVal;
  Rng rng;
};

//! Extract out common typedefs independent of the random number generator
struct SigGenBase {
  struct in_burst_t {
    int size;
    bool enable;
    double ampl;
    in_burst_t () {} // Noop
    in_burst_t (int _size, bool _enable = true, double _ampl = 1.0) :
      size (_size),
      enable (_enable),
      ampl (_ampl)
    {}
  };

  struct in_channel_t {
    vector<in_burst_t> bursts;
    double freq;
    in_channel_t () {}
    in_channel_t (int nbursts, double _freq) :
      bursts (nbursts),
      freq (_freq)
    {}
    template<typename in_t>
    in_channel_t (in_t in, in_t inend, double _freq) :
      bursts (in, inend),
      freq (_freq)
    {}
  };

  typedef vector<in_channel_t> in_frame_t;

  struct Burst {
    Burst () {}
    Burst (size_t size) : info (size) {}

    vector<int> info; //!< information bits
    double freqOff; //!< freq offset in cycles/sym
    double timeOff; //!< time offset in sym
    double phaseOff; //!< phase offset in rad
    int startOff; //!< starting position of burst in sym
    bool enable;
    double ampl; //!< amplitude (linear, voltage)
  };

  typedef vector<Burst> channel_t;
  typedef vector<channel_t> frame_t;
};

//! Signal Generator
/*!
  Given a vector of channels, each containing a list of burst lengths,
  generate PN sequences for the information to be transmitted.
*/
template<typename Rng>
class SigGen : public SigGenBase {

public:

  explicit SigGen (Rng& rng, bool _randPhase, double _fixedPhase, bool _randTiming, double _fixedTiming, bool _randFreq, double _fixedFreq, double freqSigma, bool _randStart, int _fixedStart, int _aperature) :
    phaseGen (_randPhase, _fixedPhase, boost::uniform_real<Rng> (rng, 0, 2 * M_PI)),
    timingGen (rng, 0, 1),
    freqGen (rng, 0, freqSigma),
    startGen (rng, 0, _aperature-2),
    randPhase (_randPhase),
    fixedPhase (_fixedPhase),
    randTiming (_randTiming),
    fixedTiming (_fixedTiming),
    randFreq (_randFreq),
    fixedFreq (_fixedFreq),
    randStart (_randStart),
    fixedStart (_fixedStart)
  {}

  //! Generate all bursts in all channels
  template<typename InputIterator>
  frame_t GenFrame (InputIterator channel, InputIterator channelEnd) {
    const int numChannels = channelEnd - channel;
    frame_t result (numChannels);

    for (int i = 0 ; channel != channelEnd; channel++, i++)
      result[i] = GenChannel (channel->bursts.begin(), channel->bursts.end());

    return result;
  }

private:

  //! Generate all bursts in one channel
  template<typename InputIterator>
  channel_t GenChannel (InputIterator burstSize, InputIterator burstSizeEnd) {
    const int size = burstSizeEnd - burstSize;
    channel_t result (size);

    for (int i = 0; burstSize != burstSizeEnd; burstSize++, i++)
      result[i] = GenBurst (*burstSize);

    return result;
  }

  bool randPhase;
  double fixedPhase;
  bool randTiming;
  double fixedTiming;
  bool randFreq;
  double fixedFreq;
  bool randStart;
  int fixedStart;

  maybe_random< boost::uniform_real<Rng> > phaseGen;
  boost::uniform_real<Rng> timingGen;
  boost::normal_distribution<Rng, double> freqGen;
  boost::uniform_int<Rng> startGen;
};

#endif

TestSigGen.cc:
--------------------------

#include "SigGen2.H"
#include <iostream>

using namespace std;

typedef boost::mt19937 rng_t;
typedef SigGen<rng_t> sigGen_t;

int main() {

  rng_t rng;
  
  bool randPhase = false;
  double fixedPhase = 0;
  bool randTiming = false;
  double fixedTiming = 0;
  bool randFreq = 0;
  double fixedFreq = 0;
  double freqSigma = 1e-3/3;
  bool randStart = false;
  int fixedStart = 0;
  int aperature = 1;

  sigGen_t s (rng, randPhase, fixedPhase, randTiming, fixedTiming, randFreq, fixedFreq, freqSigma, randStart, fixedStart, aperature);

}

Here's what I get:
SigGen2.H: In constructor `SigGen<Rng>::SigGen(Rng&, bool, double, bool,
   double, bool, double, double, bool, int, int) [with Rng = rng_t]':
TestSigGen2.cc:25: instantiated from here
SigGen2.H:96: no matching function for call to
   `maybe_random<boost::uniform_real<rng_t, double> >::maybe_random(bool&,
   double&, boost::uniform_real<rng_t, double>)'
SigGen2.H:22: candidates are: maybe_random<boost::uniform_real<rng_t, double>
>::maybe_random(const maybe_random<boost::uniform_real<rng_t, double> >&)
SigGen2.H:25: maybe_random<Rng>::maybe_random(bool, typename
   Rng::result_type, Rng&) [with Rng = boost::uniform_real<rng_t, double>]

On the face of it, the message doesn't seem to make sense. Isn't the
second candidate constructor (SigGen2.H:25) identical to the one which
says "no matching function for call..."?


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk