minmax_elementはvectorなどのコンテナを対象として最小値/最大値を求める。
戻り値の型はstd::pair型である。要素はポインタである。
minmaxもstd::pair型であるが、要素はminmaxのテンプレートのclass型である。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// minmax.cpp | |
// CplusplusPractice | |
// | |
// Created by masai on 2015/05/29. | |
// Copyright (c) 2015年 masai. All rights reserved. | |
// | |
#include <iostream> | |
#include <vector> | |
int main(int argc, char* argv[]){ | |
double x = 10.34, y = 3.5, z = 4.3; | |
// コンテナ | |
std::vector<double> v = {x, y, z}; | |
auto minmax = std::minmax_element(v.begin(), v.end()); | |
std::cout << "min: " << *minmax.first << std::endl; | |
std::cout << "max: " << *minmax.second << std::endl; | |
// 初期化子 | |
auto t1 = std::minmax(1,999); | |
std::cout << "min: " << t1.first << std::endl; | |
std::cout << "max: " << t1.second << std::endl; | |
} |
0 件のコメント:
コメントを投稿