当前位置: 首页>>代码示例>>C++>>正文


C++ std::fill方法代码示例

本文整理汇总了C++中std::fill方法的典型用法代码示例。如果您正苦于以下问题:C++ std::fill方法的具体用法?C++ std::fill怎么用?C++ std::fill使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在std的用法示例。


在下文中一共展示了std::fill方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main()
{
	vector<int>ivec(10);		//default initialized to 0
	fill(ivec.begin(), ivec.end(), 1);		//reset each element to 1

	//print elements in ivec
	auto iter = ivec.begin();
	while (iter != ivec.end())
		cout << *iter++ << " ";
	cout << endl;
	//sum the elements in ivec starting the summation with the value 0
	int sum = accumulate(ivec.begin(), ivec.end(), 0);
	cout << sum << endl;

	//set a subsequence of the container to 10
	fill(ivec.begin(), ivec.begin() + ivec.size() / 2, 10);
	cout << accumulate(ivec.begin(), ivec.end(), 0) << endl;

	//reset the same subsequence to 0
	fill_n(ivec.begin(), ivec.size() / 2, 0);
	cout << accumulate(ivec.begin(), ivec.end(), 0) << endl;

	//concatenates elements	in a vector of strings and store in sum
	vector<string>v;
	string s;
	while (cin >> s)
		v.push_back(s);
	string concat = accumulate(v.begin(), v.end(), string(""));
	cout << concat << endl;
	getchar();
}
开发者ID:Larry955,项目名称:learnCPP,代码行数:31,代码来源:accum.cpp

示例2: main

int main()
{
	vector<int> vec(10);              // default initialized to 0
	fill(vec.begin(), vec.end(), 1);  // reset each element to 1

	// sum the elements in vec starting the summation with the value 0
	int sum = accumulate(vec.cbegin(), vec.cend(), 0);
	cout << sum << endl;
	
	// set a subsequence of the container to 10
	fill(vec.begin(), vec.begin() + vec.size()/2, 10);
	cout << accumulate(vec.begin(), vec.end(), 0) << endl;

	// reset the same subsequence to 0
	fill_n(vec.begin(), vec.size()/2, 0);
	cout << accumulate(vec.begin(), vec.end(), 0) << endl;

	// create 10 elements on the end of vec each with the value 42
	fill_n(back_inserter(vec), 10, 42);
	cout << accumulate(vec.begin(), vec.end(), 0) << endl;
	
	// concatenate elements in a vector of strings and store in sum 
	vector<string> v;
	string s;
	while (cin >> s)
		v.push_back(s);
	string concat = accumulate(v.cbegin(), v.cend(), string(""));
	cout << concat << endl;
	
	return 0;
}
开发者ID:MGZX,项目名称:cpp_primer,代码行数:31,代码来源:accum.cpp

示例3: if

void
ZeroCopyDataSeq<Sample_T, DEF_MAX>::length(CORBA::ULong length)
{
  using std::fill;
  using std::max;
  using std::copy;

  if (length == this->length())
  {
    return;
  }

  if (is_zero_copy())
    {
      if (length < ptrs_.size())
        {
          if (!loaner_)
            {
              make_single_copy(length);
              this->length(length);
              return;
            }
          for (size_t i(length); i < ptrs_.size(); ++i)
            {
              --ptrs_[i]->zero_copy_cnt_;
              loaner_->dec_ref_data_element(ptrs_[i]);
            }
          ptrs_.resize(length, 0);
        }
      else
        {
          //There's no way we can expand the size (logical) of the zero-copy
          //array and have the user do any meaningful operations on the new
          //elements.  The fact that they're pointers to ReceivedDataElement
          //is hidden from the user.  Thus we need to make the sequence
          //single-copy at this point.
          make_single_copy(length);
        }
    }
  else
    {
      if (length < sc_length_) //shrink
        {
          sc_length_ = length;
        }
      else if (length <= sc_maximum_) //grow within buffer
        {
          fill(&sc_buffer_[sc_length_], &sc_buffer_[length], Sample_T());
          sc_length_ = length;
        }
      else //grow to larger buffer
        {
          ZeroCopyDataSeq<Sample_T, DEF_MAX> grow(max(length, sc_maximum_*2));
          copy(sc_buffer_, &sc_buffer_[sc_length_], grow.sc_buffer_);
          fill(&grow.sc_buffer_[sc_length_], &grow.sc_buffer_[length],
            Sample_T());
          swap(grow);
        }
    }
}
开发者ID:svn2github,项目名称:OpenDDS,代码行数:60,代码来源:ZeroCopySeq_T.cpp

示例4: fill

Ksf::Ksf(void)  :   m_madi( 0 ), 
    m_tick( 0 ),
    m_dummy( 0 ),
    m_track( 0 )
{
    fill( &m_bpm[0], &m_bpm[3], 0.0 );
    fill( &m_start[0], &m_start[3], 0 );
    fill( &m_bunki[0], &m_bunki[2], 0 );
}
开发者ID:beebopkim,项目名称:KickItUp,代码行数:9,代码来源:Ksf.cpp

示例5: FillBoundary

	void FillBoundary(unsigned char* image_out, int w, int h, int bpp)
	{
		const int line_stride = bpp*w;
		fill(image_out, image_out+line_stride, 0);
		for (int y = 1; y < h-1; ++y) {
			fill(image_out, image_out+bpp, 0);
			fill(image_out+line_stride-bpp, image_out+line_stride, 0);
			image_out += line_stride;
		}
		fill(image_out, image_out+line_stride, 0);
	}
开发者ID:JieFangD,项目名称:Orientation,代码行数:11,代码来源:main.cpp

示例6: test

bool test(const Problem<Scalar> &p)
{
    BOOST_TEST_MESSAGE("Testing problem " << p);

    typedef typename suzerain::traits::component<Scalar>::type component_type;
    using suzerain::complex::traits::is_complex;
    using std::abs;
    using std::copy;
    using std::fill;
    using std::partial_sum;
    using std::sqrt;

    const int N = p.S*p.n;

    // Allocate working storage
    suzerain::scoped_array<Scalar> x(new Scalar[N*abs(p.incx)]);
    suzerain::scoped_array<Scalar> y(new Scalar[N*abs(p.incy)]);
    suzerain::scoped_array<Scalar> r(new Scalar[N*abs(p.incy)]);

    // Synthesize test data
    fill(x.get(), x.get() + N*abs(p.incx), p.alpha+p.alpha+Scalar(1));
    if (is_complex<Scalar>::value) {
         fill(y.get(), y.get() + N*abs(p.incy),
              p.alpha-Scalar(7) + sqrt(Scalar(-1)));
    } else {
         fill(y.get(), y.get() + N*abs(p.incy),
              p.alpha-Scalar(7));
    }
    partial_sum(x.get(), x.get() + N*abs(p.incx), x.get());
    partial_sum(y.get(), y.get() + N*abs(p.incy), y.get());
    copy(y.get(), y.get() + N*abs(p.incy), r.get());

    // Compute the single-shot result using BSMBSM routines
    aPxpby(p, x.get(), r.get());

    // Compute same result by permuting followed by axpby
    suzerain::shared_ptr<gsl_permutation> g(suzerain_bsmbsm_permutation(p.S,p.n),
                                            &gsl_permutation_free);
    permute(p, g.get(), x.get());
    suzerain::blas::axpby(N, p.alpha, x.get(), p.incx,
                             p.beta,  y.get(), p.incy);

    // Cook a reasonable agreement tolerance
    component_type tol = std::numeric_limits<component_type>::epsilon();
    if (is_complex<Scalar>::value) tol *= 4;

    // Do r (from aPxpby) and y (from permute/axpby) agree?
    return check_close_collections(r.get(), r.get() + N*abs(p.incy),
                                   y.get(), y.get() + N*abs(p.incy),
                                   tol);
}
开发者ID:RhysU,项目名称:suzerain,代码行数:51,代码来源:test_bsmbsm.cpp

示例7: fill

void fill(symmetric_canvas<uint8_t> *grid1,symmetric_canvas<uint8_t> *grid2,
	double alpha, double exponent, double thickness, double sharpness,stripes_grid &sgr)
{
	auto gen1 = std::bind(random_levy_1d,alpha,1.);
	function<complex<double>()> gen;
	if(grid2)
		gen = [&gen1] () { return complex<double>(gen1(),gen1()); };
	else
		gen = [&gen1] () { return complex<double>(gen1(),0); };
	generate(sgr,gen,exponent);
	fill(sgr,grid1->unsafe_get_canvas(),(stripes_grid::proj_t)std::real,thickness,sharpness);
	if(grid2)
		fill(sgr,grid2->unsafe_get_canvas(),(stripes_grid::proj_t)std::imag,thickness,sharpness);
}
开发者ID:dgulotta,项目名称:paintlines,代码行数:14,代码来源:paintsquiggles.cpp

示例8: sizeof

tap::CodeHeader::CodeHeader (address init, address size,
	const std::string & filename)
{
	//memset (block, 0, sizeof (block) );
	fill (block, block + sizeof (block), byte (0) );
	block [0]= 19; // Length of block: 17 bytes + flag  + checksum
	block [1]= 0;
	block [2]= 0;  // Flag: 00 -> header
	block [3]= 3;  // Type: code block.

	// File name.
	std::string::size_type l= filename.size ();
	if (l > 10)
		l= 10;
	for (std::string::size_type i= 0; i < 10; ++i)
		block [4 + i]= i < l ? filename [i] : ' ';

	// Length of the code block.
	block [14]= lobyte (size);
	block [15]= hibyte (size);

	// Start of the code block.
	block [16]= lobyte (init);
	block [17]= hibyte (init);

	// Parameter 2: 32768 in a code block.
	block [18]= 0x00;
	block [19]= 0x80;

	// Checksum
	byte check= block [2]; // Flag byte included.
	for (int i= 3; i < 20; ++i)
		check^= block [i];
	block [20]= check;
}
开发者ID:JamesGlanville,项目名称:Z80,代码行数:35,代码来源:tap.cpp

示例9: repetition

//radius does not include center
Kernel::Kernel(int rep,int rad) : repetition(rep), radius(rad), height(2*radius +1) , width (2*radius+1)
{
  k_kernelArray = new float[height*width];
  //default is all 0
  fill(k_kernelArray, k_kernelArray+height*width, 0.f);
  factor = 0;
}
开发者ID:linzhong1992,项目名称:cs3081,代码行数:8,代码来源:Kernel.cpp

示例10: main

int main (int argc, char **argv)
{
	// Setting Server's Listen Port
	ServerPort = SERVERPORT;
	cout << "Server listening on default port " << SERVERPORT << endl;

	// Server socket.
	ServerSocketFD = socket (AF_INET, SOCK_DGRAM, 0);

	// Server address initialization for binding.
	ServerAddress.sin_family = AF_INET;				// Socekt family.
	ServerAddress.sin_addr.s_addr = INADDR_ANY;		// Setting server IP. INADDR_ANY is the localhost IP.
	ServerAddress.sin_port = htons (ServerPort);	// Setting server port.
	fill ((char*)&(ServerAddress.sin_zero), (char*)&(ServerAddress.sin_zero)+8, '\0');

	// bind()
	bind (ServerSocketFD, (sockaddr *)&ServerAddress, sizeof (ServerAddress));

	// recvfrom() is blocking and will wait for any messages from client.
	socklen_t ClientAddressSize = sizeof (ClientAddress);
	NumOfBytesReceived = recvfrom (ServerSocketFD, Buffer, MAXBUFFERSIZE-1, 0, (sockaddr *)&ClientAddress, &ClientAddressSize);

	Buffer[NumOfBytesReceived] = '\0';
	cout << "Server got packet from " << inet_ntoa (ClientAddress.sin_addr) << " on socket " << ServerSocketFD << endl;
	cout << "Client says: " << Buffer << endl;

	// sendto()
	char ServerMessage[] = "Hello from Server. Now bye!";
	NumOfBytesSent = sendto (ServerSocketFD, ServerMessage, strlen (ServerMessage), 0, (sockaddr *)&ClientAddress, sizeof (ClientAddress));

	// Close connection.
	close (ServerSocketFD);
	return 0;
}
开发者ID:inf-eth,项目名称:i02-0491-courses,代码行数:34,代码来源:Server.cpp

示例11: PrimeSieve

std::vector<bool>* PrimeSieve(const int64_t& LENGTH) {
    using std::ceil;
    using std::fill;
    using std::sqrt;
    using std::vector;
    // Fill with true
    vector<bool>* primes = new vector<bool>(LENGTH);
    fill(primes->begin(), primes->end(), true);

    // 0, 1 are not prime
    if (LENGTH >= 2) {
        primes->at(0) = primes->at(1) = false;
    } else if (LENGTH < 1) {
        return NULL;
    } else {
        primes->at(0) = false;
    }

    // Sieve
    for (int64_t i = 2; i < ceil(sqrt(LENGTH)); ++i) {
        if (primes->at(i)) {
            for (int64_t j = i * i; j < LENGTH; j += i) {
                primes->at(j) = false;
            }
        }
    }
    return primes;
}
开发者ID:agude,项目名称:Project-Euler,代码行数:28,代码来源:alexlib.cpp

示例12: none

treatment::treatment(const real_t& Ma,
                     const pencil_grid& dgrid,
                     bspline& b,
                     inputs& inp,
                     outputs& out)
    : none(new constraint::disabled(b))
    , Ma(Ma)
    , rank_has_zero_zero_modes(dgrid.has_zero_zero_modes())
    , inp(inp)
    , out(out)
    , jacobiSvd(0, 0, Eigen::ComputeFullU | Eigen::ComputeFullV)
{
    using std::fill;
    fill(physical.begin(),  physical.end(),  none);
    fill(numerical.begin(), numerical.end(), none);
}
开发者ID:RhysU,项目名称:suzerain,代码行数:16,代码来源:treatment_constraint.cpp

示例13: ApplicationType

INGR_TileHeader::INGR_TileHeader() :
    ApplicationType(0),
    SubTypeCode(0),
    WordsToFollow(0),
    PacketVersion(0),
    Identifier(0),
    Properties(0),
    DataTypeCode(0),
    TileSize(0),
    Reserved3(0)
{
    fill( Reserved, Reserved + CPL_ARRAYSIZE(Reserved), 0 );
    fill( Reserved2, Reserved2 + CPL_ARRAYSIZE(Reserved2), 0 );
    First.Start = 0;
    First.Allocated = 0;
    First.Used = 0;
}
开发者ID:garnertb,项目名称:gdal,代码行数:17,代码来源:IntergraphBand.cpp

示例14: _invalidate_names

	static
	void _invalidate_names(Container& names)
	{
		using std::fill;
		using std::begin;
		using std::end;
		fill(begin(names), end(names), _traits::invalid_name());
	}
开发者ID:matus-chochlik,项目名称:oglplu2,代码行数:8,代码来源:names.hpp

示例15: resize

void CoverageMap::resize ( int protLen )
{
    error = ( protLen == 0 );
    if ( !error ) {
        aaCovered.resize ( protLen );
        fill ( aaCovered.begin (), aaCovered.end (), false );
    }
}
开发者ID:proteinprospector,项目名称:prospector,代码行数:8,代码来源:lu_coverage.cpp


注:本文中的std::fill方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。