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


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

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


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

示例1: main

int main() {

    cout << plus<int>()(3,4) << endl; // prints 7

    plus<int> intAdd;        // function object that can add two int values
    negate<int>  intNegate;  // function object that can negate an int value

    // uses intAdd::operator(int, int) to add 10 and 20
    int sum = intAdd(10, 20);        // sum = 30

    cout << sum << endl;

    // uses intNegate::operator(int) to generate -10 as second parameter
    // to intAdd::operator(int, int)
    sum = intAdd(10, intNegate(10));  // sum = 0

    cout << sum << endl;

    int arry[] = {0,1,2,3,4,5,16,17,18,19};

    vector<int> vec(arry, arry + 10);

    cout <<
    count_if(vec.begin(), vec.end(),
             bind2nd(less_equal<int>(), 10));
    cout << endl;

    cout <<
    count_if(vec.begin(), vec.end(),
             not1(bind2nd(less_equal<int>(), 10)));
    cout << endl;

    return 0;
}
开发者ID:CurvaVita,项目名称:C--------C---Primer--,代码行数:34,代码来源:fcnobj.cpp

示例2: main

int main()
{
  vector< int > v;
  v.push_back(3);
  v.push_back(5);
  v.push_back(2);
  cout << "min_odd = "
       << *min_element_if(v.begin(),
			  v.end(),
			  compose1_1(bind2nd(greater< int >(), 0),
				     bind2nd(modulus< int >(), 2)))
       << endl;
  return 0;
}
开发者ID:Asuzer,项目名称:cgal,代码行数:14,代码来源:min_element_if_example.cpp

示例3: SQFR

PPMonoidElem SQFR(ConstRefPPMonoidElem T)
{
  vector<long> expv;
  exponents(expv,T);
  replace_if(expv.begin(),expv.end(),bind2nd(not_equal_to<long>(),0),1);
  return PPMonoidElem(owner(T),expv);
}//SQFR
开发者ID:BrentBaccala,项目名称:CoCoA,代码行数:7,代码来源:test-Dynamic1.C

示例4: generate

BVHAccelTreeNode *BVHAccel::BuildHierarchy(vector<BVHAccelTreeNode *> &list, unsigned int begin, unsigned int end, unsigned int axis) {


	const int treeType = 4; // Tree type to generate (2 = binary, 4 = quad, 8 = octree)


	unsigned int splitAxis = axis;
	float splitValue;

	nNodes += 1;
	if (end - begin == 1) // Only a single item in list so return it
		return list[begin];

	BVHAccelTreeNode *parent = new BVHAccelTreeNode();
	parent->primitive = 0xffffffffu;
	parent->leftChild = NULL;
	parent->rightSibling = NULL;

	vector<unsigned int> splits;
	splits.reserve(treeType + 1);
	splits.push_back(begin);
	splits.push_back(end);
	for (unsigned int i = 2; i <= treeType; i *= 2) { // Calculate splits, according to tree type and do partition
		for (unsigned int j = 0, offset = 0; j + offset < i && splits.size() > j + 1; j += 2) {
			if (splits[j + 1] - splits[j] < 2) {
				j--;
				offset++;
				continue; // Less than two elements: no need to split
			}

			FindBestSplit(list, splits[j], splits[j + 1], &splitValue, &splitAxis);

			vector<BVHAccelTreeNode *>::iterator it =
					partition(list.begin() + splits[j], list.begin() + splits[j + 1], bind2nd(ptr_fun(bvh_ltf[splitAxis]), splitValue));
			unsigned int middle = distance(list.begin(), it);
			middle = max(splits[j] + 1, min(splits[j + 1] - 1, middle)); // Make sure coincidental BBs are still split
			splits.insert(splits.begin() + j + 1, middle);
		}
	}

	BVHAccelTreeNode *child, *lastChild;
	// Left Child
	child = BuildHierarchy(list, splits[0], splits[1], splitAxis);
	parent->leftChild = child;
	parent->bbox = child->bbox;
	lastChild = child;

	// Add remaining children
	for (unsigned int i = 1; i < splits.size() - 1; i++) {
		child = BuildHierarchy(list, splits[i], splits[i + 1], splitAxis);
		lastChild->rightSibling = child;
		parent->bbox = Union(parent->bbox, child->bbox);
		lastChild = child;
	}

	return parent;
}
开发者ID:naps62,项目名称:papi-cuda,代码行数:57,代码来源:bvhaccel.cpp

示例5:

bool
Matrix::is_count_mat() const {
  // TODO: this needs to be much more robust, or maybe we need to have
  // a 3 way split: matrices can be freq or count, or just plain wrong
  for (Matrix::const_iterator i = begin(); i != end(); ++i)
    if (find_if(*i, *i + alphabet_size, bind2nd(greater<float>(), 1)) 
	!= *i + alphabet_size)
      return true;
  return false;
}
开发者ID:chenliangomc,项目名称:dme2redist,代码行数:10,代码来源:Matrix.cpp

示例6:

Value * FunctionCallNode::GenerateCode (CodeGeneratorState & state) const {
	Function * callee = state.module->getFunction (this->name.c_str ());
	if (NULL == callee)
		throw "Unknown function called";

	if (callee->arg_size () != this->params->size ())
		throw "Prototype mismatch";

	vector <Value *> arguments;
	arguments.reserve (this->params->size ());
	transform (this->params->begin (), this->params->end (), back_inserter (arguments), bind2nd (mem_fun (& IASTNode::GenerateCode), state));

	return state.builder->CreateCall (callee, arguments.begin (), arguments.end (), "tmp");
}
开发者ID:victorsamun,项目名称:compiler,代码行数:14,代码来源:FunctionCallNode.cpp

示例7: Evaluate

float StageClassifier::Evaluate(vector<vector<vector<float>>>& X, vector<bool>& y)
{
    vector<float> probs;
    vector<float> TPRs, FPRs;
    float area = 0;

    for (int i = 0; i < X.size(); i++)
        probs.push_back(Predict(X[i]));

    /* test on training set (0.5 threshhold??) */
    //#if SETLEVEL == DEBUG_LEVEL
    //int TP = 0, TN = 0;
    //for (int i = 0; i < X.size(); i++)
    //{
    //    if ((probs[i] >= 0.5) && y[i] == true)
    //        TP++;
    //    else if ((probs[i] < 0.5) && y[i] == false)
    //        TN++;
    //}
    //LOG_DEBUG_NN("\t\tStrong classifier: ");
    //LOG_DEBUG_NN("TP = " << TP << '/' << y.size() / 2 << ", TN = " << TN << '/' << y.size() / 2);
    //LOG_DEBUG_NN(", Result: " << (float)(TP + TN) / y.size());
    //#endif

    for (float threshhold = 1; threshhold >= 0; threshhold -= auc_step)
    {
        TPRs.push_back(count_if(probs.begin(), probs.begin() + n_pos, bind2nd(greater_equal<float>(), threshhold)) / (float)n_pos);
        FPRs.push_back(count_if(probs.begin() + n_pos, probs.end(), bind2nd(greater_equal<float>(), threshhold)) / (float)n_neg);

        if (FPRs.size() > 1)
            area += (TPRs.back() + TPRs[TPRs.size() - 2]) * (FPRs.back() - FPRs[FPRs.size() - 2]) / 2; // trapezoid
            //area += TPRs[TPRs.size() - 2] * (FPRs.back() - FPRs[FPRs.size() - 2]); // left riemann sum
            //area += TPRs.back() * (FPRs.back() - FPRs[FPRs.size() - 2]); // right Riemann sum
    }

    return area;
}
开发者ID:mrgloom,项目名称:SurfCascade,代码行数:37,代码来源:StageClassifier.cpp

示例8: SearchTheta

void StageClassifier::SearchTheta(vector<vector<vector<float>>>& X, vector<bool>& y)
{
    int whole_n_total = (int)y.size();
    int whole_n_pos = (int)count(y.begin(), y.end(), true);
    int whole_n_neg = (int)(whole_n_total - whole_n_pos);

    vector<float> probs;

    for (int i = 0; i < X.size(); i++)
        probs.push_back(Predict(X[i]));

    /* search min TPR */
    float threshhold;
    for (threshhold = 1; threshhold >= 0; threshhold -= search_step)
    {
        TPR = count_if(probs.begin(), probs.begin() + whole_n_pos, bind2nd(greater_equal<float>(), threshhold)) / (float)whole_n_pos;
        if (TPR >= TPR_min)
            break;
    }

    /* get corresponding theta and FPR */
    theta = threshhold;
    FPR = count_if(probs.begin() + whole_n_pos, probs.end(), bind2nd(greater_equal<float>(), threshhold)) / (float)whole_n_neg;
}
开发者ID:mrgloom,项目名称:SurfCascade,代码行数:24,代码来源:StageClassifier.cpp

示例9: is_undef

bool Coff_object::is_undef(const char a_sym[]) const
{
    using std::find_if;
    using std::not1;
    using std::bind2nd;
    using std::ptr_fun;
    using std::strcmp;

    typedef std::vector<const char*> T;

    T::const_iterator beg_p = m_undef_symbols.begin();
    T::const_iterator end_p = m_undef_symbols.end();

    T::const_iterator pos = find_if( beg_p, end_p, not1(bind2nd( ptr_fun(strcmp), a_sym)) );

    return (pos != end_p);
}
开发者ID:fedor4ever,项目名称:linux_build,代码行数:17,代码来源:coff_object.cpp

示例10: main

int main(int argc, char *argv[])
{
    double duty = 0.5;
    if (argc > 1)
    {
        duty = std::atof(argv[1]);
    }

    // sample frequency is fixed at 1 kHz, signal frequency at 10 Hz
    Aquila::SquareGenerator gen(1000);
    gen.setDuty(duty).setAmplitude(1).setFrequency(10).generate(1000);

    // prints number of positive samples in generated signal
    std::cout << count_if(gen.begin(), gen.end(),
                          bind2nd(greater<Aquila::SampleType>(), 0));

    return 0;
}
开发者ID:sequoiar,项目名称:aquila,代码行数:18,代码来源:sg_duty_cycle.cpp

示例11: fill

Matrix
Matrix::combine(const Matrix &matrix1, const Matrix &matrix2, int offset) {
  Matrix newmat;
  newmat.width = std::max(matrix1.width,
			  matrix2.width + offset);
  newmat.matrix = new float*[newmat.width];
  for (size_t i = 0; i < newmat.width; ++i) {
    newmat.matrix[i] = new float[alphabet_size];
    fill(newmat.matrix[i], newmat.matrix[i] + alphabet_size, 0);
  }
  for (size_t i = 0; i < matrix1.width; ++i)
    for (size_t j = 0; j < alphabet_size; ++j)
      newmat.matrix[i][j] += matrix1.matrix[i][j];
  for (size_t i = 0; i < matrix2.width; ++i)
    for (size_t j = 0; j < alphabet_size; ++j)
      newmat.matrix[i + offset][j] += matrix2.matrix[i][j];
  for (size_t i = 0; i < newmat.width; ++i) {
    const float total = accumulate(newmat.matrix[i],
				   newmat.matrix[i] + alphabet_size, 0.0);
    transform(newmat.matrix[i], newmat.matrix[i] + alphabet_size,
	      newmat.matrix[i], bind2nd(divides<float>(), total));
  }
  return newmat;
}
开发者ID:chenliangomc,项目名称:dme2redist,代码行数:24,代码来源:Matrix.cpp

示例12:

void	BBCutter::SetFillDutyCycle(float v) { for_each(procs.begin(),procs.end(),bind2nd(mem_fun(&CutProc::SetFillDutyCycle),v));}
开发者ID:mdsp,项目名称:Livecut,代码行数:1,代码来源:BBCutter.cpp

示例13: inserter

DtxAck::DtxAck(const qpid::framing::SequenceSet& acked, DeliveryRecords& unacked)
{
    remove_copy_if(unacked.begin(), unacked.end(), inserter(pending, pending.end()), 
                   not1(bind2nd(mem_fun_ref(&DeliveryRecord::coveredBy), &acked)));
}
开发者ID:ChugR,项目名称:qpid-cpp,代码行数:5,代码来源:DtxAck.cpp

示例14:

Value * ASTNodesListNode::GenerateCode (CodeGeneratorState & state) const {
	for_each (this->exprs.begin (), this->exprs.end (), bind2nd (mem_fun (& IASTNode::GenerateCode), state));
}
开发者ID:victorsamun,项目名称:compiler,代码行数:3,代码来源:ASTNodesListNode.cpp


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